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);
        }
        public void ValueSerializationIsBase64()
        {
            var serializer = new StringKeySerializer();

            Assert.Equal("AQID", serializer.SerializeAsKey(new FixedBinaryValueSerializer(new byte[] { 1, 2, 3 }, KumoDictionaryValueSerialization.Binary), default(MyClass)));
        }
        public void SerializeEnum()
        {
            var serializer = new StringKeySerializer();

            Assert.Equal("5678", serializer.SerializeAsKey(null, MyEnum.B));
        }
        public void ValueSerializationIsRawString()
        {
            var serializer = new StringKeySerializer();

            Assert.Equal("{\"Key\":123}", serializer.SerializeAsKey(new FixedBinaryValueSerializer(new UTF8Encoding(false).GetBytes("{\"Key\":123}"), KumoDictionaryValueSerialization.String), default(MyClass)));
        }
示例#5
0
 public BinaryDictionaryTableEntity(string partitionKey, TKey rowKey, TValue value, IKumoDictionaryValueSerializer serializer, StringKeySerializer keySerializer)
 {
     PartitionKey = partitionKey;
     RowKey       = keySerializer.SerializeAsKey(serializer, rowKey);
     RawValue     = serializer.Serialize(value);
 }
示例#6
0
 public StringDictionaryTableEntity(string partitionKey, TKey rowKey, TValue value, IKumoDictionaryValueSerializer serializer, StringKeySerializer keySerializer)
 {
     PartitionKey = partitionKey;
     RowKey       = keySerializer.SerializeAsKey(serializer, rowKey);
     RawValue     = new UTF8Encoding(false).GetString(serializer.Serialize(value));
 }