public void ListOfStructsAsListOfDoubles() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(2, 1, 0); ds.ListBuildStruct(0).WriteData(0, double.NegativeInfinity); ds.ListBuildStruct(1).WriteData(0, double.MaxValue); DeserializerState d = ds; var asListOfDoubles = d.RequireList().CastDouble(); Assert.AreEqual(2, asListOfDoubles.Count); Assert.AreEqual(double.NegativeInfinity, asListOfDoubles[0]); Assert.AreEqual(double.MaxValue, asListOfDoubles[1]); }
public void ListOfStructsAsListOfLongs() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(2, 1, 0); ds.ListBuildStruct(0).WriteData(0, long.MinValue); ds.ListBuildStruct(1).WriteData(0, long.MaxValue); DeserializerState d = ds; var asListOfLongs = d.RequireList().CastLong(); Assert.AreEqual(2, asListOfLongs.Count); Assert.AreEqual(long.MinValue, asListOfLongs[0]); Assert.AreEqual(long.MaxValue, asListOfLongs[1]); }
public void ListOfStructsAsListOfFloats() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(2, 1, 0); ds.ListBuildStruct(0).WriteData(0, float.NaN); ds.ListBuildStruct(1).WriteData(0, float.PositiveInfinity); DeserializerState d = ds; var asListOfFloats = d.RequireList().CastFloat(); Assert.AreEqual(2, asListOfFloats.Count); Assert.AreEqual(float.NaN, asListOfFloats[0]); Assert.AreEqual(float.PositiveInfinity, asListOfFloats[1]); }
public void ListOfStructsAsListOfBytes() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(3, 1, 0); ds.ListBuildStruct(1).WriteData(0, (byte)0x11); ds.ListBuildStruct(2).WriteData(0, (byte)0x22); DeserializerState d = ds; var asListOfBytes = d.RequireList().CastByte(); Assert.AreEqual(3, asListOfBytes.Count); Assert.AreEqual(0, asListOfBytes[0]); Assert.AreEqual((byte)0x11, asListOfBytes[1]); Assert.AreEqual((byte)0x22, asListOfBytes[2]); }
public void ListOfStructsAsListOfBools() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(3, 1, 0); ds.ListBuildStruct(1).WriteData(0, false); ds.ListBuildStruct(2).WriteData(0, true); DeserializerState d = ds; var asListOfBools = d.RequireList().CastBool(); Assert.AreEqual(3, asListOfBools.Count); Assert.AreEqual(false, asListOfBools[0]); Assert.AreEqual(false, asListOfBools[1]); Assert.AreEqual(true, asListOfBools[2]); }
public void ListOfStructs() { var mb = MessageBuilder.Create(1); var alloc = mb.Allocator; var ds = new DynamicSerializerState(mb); int count = 23; ds.SetListOfStructs(count, 2, 1); var dse0 = ds.ListBuildStruct(0); dse0.WriteData(0, 1); dse0.WriteData(64, 2); var dse1 = ds.ListBuildStruct(1); dse1.WriteData(0, 3); dse1.WriteData(64, 4); Assert.ThrowsException <InvalidOperationException>( () => ds.Link(2, ds)); Assert.ThrowsException <InvalidOperationException>( () => ds.BuildPointer(2)); DeserializerState d = ds; Assert.AreEqual(ObjectKind.ListOfStructs, d.Kind); Assert.AreEqual(count, d.ListElementCount); var pointers = d.RequireList().Cast(_ => _); Assert.AreEqual(ObjectKind.Struct, pointers[0].Kind); Assert.AreEqual(1, pointers[0].ReadDataInt(0)); Assert.AreEqual(2, pointers[0].ReadDataInt(64)); Assert.AreEqual(ObjectKind.Struct, pointers[1].Kind); Assert.AreEqual(3, pointers[1].ReadDataInt(0)); Assert.AreEqual(4, pointers[1].ReadDataInt(64)); Assert.AreEqual(ObjectKind.Struct, pointers[2].Kind); Assert.AreEqual(0, pointers[2].ReadDataInt(0)); Assert.AreEqual(0, pointers[2].ReadDataInt(64)); Assert.ThrowsException <IndexOutOfRangeException>(() => { var dummy = pointers[-1]; }); Assert.ThrowsException <IndexOutOfRangeException>(() => { var dummy = pointers[count]; }); }
public void ListOfStructsAsListOfUShorts() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(2, 1, 0); ds.ListBuildStruct(1).WriteData(0, ushort.MaxValue); DeserializerState d = ds; var asListOfUShorts = d.RequireList().CastUShort(); Assert.AreEqual(2, asListOfUShorts.Count); Assert.AreEqual((ushort)0, asListOfUShorts[0]); Assert.AreEqual(ushort.MaxValue, asListOfUShorts[1]); }
public void ListOfStructsAsListOfSBytes() { var ds = new DynamicSerializerState(MessageBuilder.Create(128)); ds.SetListOfStructs(2, 1, 0); ds.ListBuildStruct(1).WriteData(0, sbyte.MinValue); DeserializerState d = ds; var asListOfSBytes = d.RequireList().CastSByte(); Assert.AreEqual(2, asListOfSBytes.Count); Assert.AreEqual((sbyte)0, asListOfSBytes[0]); Assert.AreEqual(sbyte.MinValue, asListOfSBytes[1]); }