Ejemplo n.º 1
0
        public void Should_Deserialize_Non_Value_Type_Fields()
        {
            var mapping = ObjectSerializationMapper.Create()
                          .FromType <NonValueTypeFieldTestClass>()
                          .PublicFields()
                          .Map();

            var deserializationOps = ObjectSerializerCompiler.CompileDeserializationOps(mapping).ToList().AsReadOnly();

            var context = ObjectSerializerInterpreter.InterpretObjectSerializationNullContext(
                typeof(NonValueTypeFieldTestClass),
                deserializationOps,
                ObjectSerializerProgram.GetOpValueSerializerTypes(deserializationOps).ToList().AsReadOnly()
                );

            var deserializeDelegate = ObjectSerializerInterpreter.InterpretDynamicDeserializeDelegate(
                context,
                typeof(NonValueTypeFieldTestClass),
                deserializationOps
                );

            var stringSerializer   = new StringSerializer();
            var bitFieldSerializer = new BitFieldSerializer();
            var nullMask           = new BitField(1);

            nullMask.SetBit(0, true);

            var buffer = new byte[64];
            var offset = 0;

            bitFieldSerializer.Serialize(nullMask, buffer, offset);
            offset += bitFieldSerializer.GetSizeFromValue(nullMask);

            // X.
            MemoryMapper.WriteInt(25, buffer, offset);
            offset += sizeof(int);

            // Y.
            MemoryMapper.WriteInt(50, buffer, offset);
            offset += sizeof(int);

            // S2.
            stringSerializer.Serialize("hello!", buffer, offset);

            var results = (NonValueTypeFieldTestClass)deserializeDelegate(context, buffer, 0);

            Assert.Equal(25, results.X);
            Assert.Equal(50, results.Y);
            Assert.Equal("hello!", results.S2);

            Assert.Null(results.S1);

            Assert.True(string.IsNullOrEmpty(results.Null));
        }
Ejemplo n.º 2
0
        public void Should_Deserialize_Nullable_Properties()
        {
            var mapping = ObjectSerializationMapper.Create()
                          .FromType <NullablePropertyTestClass>()
                          .PublicProperties()
                          .Map();

            var deserializationOps = ObjectSerializerCompiler.CompileDeserializationOps(mapping).ToList().AsReadOnly();

            var context = ObjectSerializerInterpreter.InterpretObjectSerializationNullContext(
                typeof(NullablePropertyTestClass),
                deserializationOps,
                ObjectSerializerProgram.GetOpValueSerializerTypes(deserializationOps).ToList().AsReadOnly()
                );

            var deserializeDelegate = ObjectSerializerInterpreter.InterpretDynamicDeserializeDelegate(
                context,
                typeof(NullablePropertyTestClass),
                deserializationOps
                );

            var bitFieldSerializer = new BitFieldSerializer();
            var nullMask           = new BitField(1);

            nullMask.SetBit(0, true);

            var buffer = new byte[32];
            var offset = 0;

            bitFieldSerializer.Serialize(nullMask, buffer, offset);
            offset += bitFieldSerializer.GetSizeFromValue(nullMask);

            MemoryMapper.WriteInt(50, buffer, offset);
            offset += sizeof(int);

            MemoryMapper.WriteInt(75, buffer, offset);
            offset += sizeof(int);

            MemoryMapper.WriteInt(100, buffer, offset);

            var results = (NullablePropertyTestClass)deserializeDelegate(context, buffer, 0);

            Assert.Equal(50, results.I);
            Assert.Equal(75, results.X);
            Assert.Equal(100, results.J);
        }
Ejemplo n.º 3
0
 public void Get_Size_From_Value_Returns_Bit_Field_Size_In_And_Size_Field_Bytes()
 {
     Assert.Equal(17, BitFieldSerializer.GetSizeFromValue(new BitField(16)));
 }