public void SerializeDeserializeComplexType()
        {
            var serializer      = new StringKeySerializer();
            var valueSerializer = new MessagePackValueSerializer();

            var value = new MyClass
            {
                PropBool   = true,
                PropString = "Hello コンニチハ!",
                FieldA     = 123456,
                Inner      = new MyClass.MyStruct
                {
                    Value = Guid.NewGuid()
                }
            };

            var serializeDirectly   = Convert.ToBase64String(MessagePack.LZ4MessagePackSerializer.Serialize(value, MessagePack.Resolvers.ContractlessStandardResolver.Instance));
            var deserializeDirectly = MessagePack.LZ4MessagePackSerializer.Deserialize <MyClass>(Convert.FromBase64String(serializeDirectly), MessagePack.Resolvers.ContractlessStandardResolver.Instance);

            var serialized = serializer.SerializeAsKey(valueSerializer, value);

            Assert.NotNull(serialized);
            Assert.Equal(serializeDirectly, serialized);

            var deserialized = serializer.DeserializeFromKey <MyClass>(valueSerializer, serialized);

            Assert.Equal(value.PropString, deserialized.PropString);
            Assert.Equal(value.PropBool, deserialized.PropBool);
            Assert.Equal(value.FieldA, deserialized.FieldA);
            Assert.Equal(value.Inner.Value, deserialized.Inner.Value);
        }
Пример #2
0
        public void VerifyDefaultSettings()
        {
            var valueSerializer = new MessagePackValueSerializer();

            Assert.True(valueSerializer.EnableLZ4Compression);
            Assert.Equal(MessagePack.Resolvers.ContractlessStandardResolver.Instance, valueSerializer.Resolver);
        }