Esempio n. 1
0
        public void StructWithPrimitives()
        {
            var mb    = MessageBuilder.Create(8);
            var alloc = mb.Allocator;
            var ds    = new DynamicSerializerState(mb);

            ds.SetStruct(10, 0);
            ds.WriteData(0, ulong.MaxValue - 1, ulong.MaxValue);
            ds.WriteData(64, long.MaxValue - 1, -123);
            ds.WriteData(128, uint.MaxValue - 1, 123);
            ds.WriteData(160, int.MaxValue - 1, -123);
            ds.WriteData(192, (ushort)(ushort.MaxValue - 1), (ushort)321);
            ds.WriteData(208, (short)(short.MaxValue - 1), (short)321);
            ds.WriteData(224, (byte)(byte.MaxValue - 1), (byte)111);
            ds.WriteData(232, (sbyte)(sbyte.MaxValue - 1), (sbyte)(-111));
            ds.WriteData(240, false, false);
            ds.WriteData(241, false, true);
            ds.WriteData(242, true, false);
            ds.WriteData(243, true, true);
            ds.WriteData(256, 12.34, 0.5);
            ds.WriteData(320, 1.2f, 0.5f);

            DeserializerState d = ds;

            Assert.AreEqual(ulong.MaxValue - 1, d.ReadDataULong(0, ulong.MaxValue));
            Assert.AreEqual(long.MaxValue - 1, d.ReadDataLong(64, -123));
            Assert.AreEqual(uint.MaxValue - 1, d.ReadDataUInt(128, 123));
            Assert.AreEqual(int.MaxValue - 1, d.ReadDataInt(160, -123));
            Assert.AreEqual(ushort.MaxValue - 1, d.ReadDataUShort(192, 321));
            Assert.AreEqual(short.MaxValue - 1, d.ReadDataShort(208, 321));
            Assert.AreEqual(byte.MaxValue - 1, d.ReadDataByte(224, 111));
            Assert.AreEqual(sbyte.MaxValue - 1, d.ReadDataSByte(232, -111));
            Assert.AreEqual(false, d.ReadDataBool(240, false));
            Assert.AreEqual(false, d.ReadDataBool(241, true));
            Assert.AreEqual(true, d.ReadDataBool(242, false));
            Assert.AreEqual(true, d.ReadDataBool(243, true));
            Assert.AreEqual(12.34, d.ReadDataDouble(256, 0.5));
            Assert.AreEqual(1.2f, d.ReadDataFloat(320, 0.5f));
        }