Example #1
0
        private static T DeserializeByClassicMsgPack <T>(byte[] messagePackBytes, MsgPack.Serialization.SerializationMethod method)
        {
            var context = new MsgPack.Serialization.SerializationContext
            {
                SerializationMethod  = method,
                CompatibilityOptions = { PackerCompatibilityOptions = MsgPack.PackerCompatibilityOptions.Classic },
            };

            var messagePackSerializer = MsgPack.Serialization.MessagePackSerializer.Get <T>(context);

            using (var memory = new MemoryStream(messagePackBytes))
            {
                return(messagePackSerializer.Unpack(memory));
            }
        }
Example #2
0
        private static byte[] SerializeByClassicMsgPack <T>(T obj, MsgPack.Serialization.SerializationMethod method)
        {
            var context = new MsgPack.Serialization.SerializationContext
            {
                SerializationMethod  = method,
                CompatibilityOptions = { PackerCompatibilityOptions = MsgPack.PackerCompatibilityOptions.Classic },
            };

            var messagePackSerializer = MsgPack.Serialization.MessagePackSerializer.Get <T>(context);

            using (var memory = new MemoryStream())
            {
                messagePackSerializer.Pack(memory, obj);
                return(memory.ToArray());
            }
        }