private static void RunOnce() { using (var stream = new MemoryStream()) { using (var writer = new ManagedBinaryWriter(stream, Symbols.EmptySymbolTablesArray)) { writer.StepIn(IonType.List); for (var i = 0; i < 1000; i++) { writer.StepIn(IonType.Struct); writer.SetFieldName("boolean"); writer.WriteBool(true); writer.SetFieldName("string"); writer.WriteString("this is a string"); writer.SetFieldName("integer"); writer.WriteInt(int.MaxValue); writer.SetFieldName("float"); writer.WriteFloat(432.23123f); writer.SetFieldName("timestamp"); writer.WriteTimestamp(new Timestamp(new DateTime(2000, 11, 11))); writer.StepOut(); } writer.StepOut(); writer.Flush(); } } }
public void WriteSingleBool(bool val) { using (var writer = new ManagedBinaryWriter(_memoryStream, Symbols.EmptySymbolTablesArray)) { writer.WriteBool(val); writer.Flush(); var bytes = _memoryStream.GetWrittenBuffer(); Assert.AreEqual(val, ReadUtils.Binary.ReadSingleBool(bytes)); } }
public void WriteSingleBool(bool val) { using (var stream = new MemoryStream()) { using (var writer = new ManagedBinaryWriter(BinaryConstants.EmptySymbolTablesArray)) { writer.WriteBool(val); writer.Flush(stream); var bytes = stream.ToArray(); Assert.AreEqual(val, ReadUtils.Binary.ReadSingleBool(bytes)); } } }
public void Run(string[] args) { var outputStream = new MemoryStream(); var writer = new ManagedBinaryWriter(new ISymbolTable[0]); writer.StepIn(IonType.Struct); writer.SetFieldName("yes"); writer.WriteBool(true); writer.SetFieldName("strings"); writer.WriteString("abcd def adsd dasdas tiếng việt 😂"); writer.SetFieldName("number_struct"); writer.StepIn(IonType.Struct); writer.SetFieldName("number"); writer.WriteInt(int.MaxValue / 2); writer.StepOut(); writer.SetFieldName("float_min"); writer.WriteFloat(float.MinValue); writer.SetFieldName("float_rand"); writer.WriteFloat(float.MaxValue / 2); writer.SetFieldName("double_max"); writer.WriteFloat(double.MaxValue); writer.SetFieldName("double_rand"); writer.WriteFloat(3.12345678901); writer.StepOut(); writer.WriteInt(int.MaxValue); writer.Flush(outputStream); writer.Dispose(); var bytes = outputStream.ToArray(); Console.WriteLine(bytes.Length); Console.WriteLine(string.Join(" ", bytes.Select(b => $"{b:X2}"))); var reader = new UserBinaryReader(new MemoryStream(bytes)); reader.MoveNext(); Console.WriteLine(reader.CurrentType); reader.StepIn(); reader.MoveNext(); Console.WriteLine(reader.CurrentFieldName); Console.WriteLine(reader.CurrentType); Console.WriteLine(reader.BoolValue()); Console.WriteLine(); reader.MoveNext(); Console.WriteLine(reader.CurrentFieldName); Console.WriteLine(reader.CurrentType); Console.WriteLine(reader.StringValue()); Console.WriteLine(); reader.MoveNext(); Console.WriteLine(reader.CurrentFieldName); Console.WriteLine(reader.CurrentType); reader.StepIn(); reader.MoveNext(); Console.WriteLine(reader.CurrentFieldName); Console.WriteLine(reader.CurrentType); Console.WriteLine(reader.IntValue()); reader.StepOut(); reader.MoveNext(); Console.WriteLine(reader.CurrentFieldName); Console.WriteLine(reader.CurrentType); Console.WriteLine(reader.DoubleValue()); Console.WriteLine(); reader.MoveNext(); Console.WriteLine(reader.CurrentFieldName); Console.WriteLine(reader.CurrentType); Console.WriteLine(reader.DoubleValue()); Console.WriteLine(); reader.MoveNext(); Console.WriteLine(reader.CurrentFieldName); Console.WriteLine(reader.CurrentType); Console.WriteLine(reader.DoubleValue()); Console.WriteLine(); reader.MoveNext(); Console.WriteLine(reader.CurrentFieldName); Console.WriteLine(reader.CurrentType); Console.WriteLine(reader.DoubleValue()); Console.WriteLine(); }