object DeserializeInner(Stream stream, IList <Type> messageTypes)
        {
            var messageType = messageTypes.First();

            var           typeHandle = messageType.TypeHandle;
            Func <object> constructor;

            if (emptyTypesBag.TryGetValue(typeHandle, out constructor))
            {
                return(constructor());
            }
            MsgPack.Serialization.MessagePackSerializer serializer;
            try
            {
                serializer = context.GetSerializer(messageType);
            }
            catch (SerializationException exception)
                when(IsEmptyTypeException(exception))
                {
                    constructor = emptyTypesBag.GetOrAdd(
                        key: typeHandle,
                        valueFactory: handle => ConstructorDelegateBuilder.BuildConstructorFunc(messageType));
                    return(constructor());
                }

            return(serializer.Unpack(stream));
        }
        public void Serialize(object message, Stream stream)
        {
            var messageType = message.GetType();

            if (messageType.Name.EndsWith("__impl"))
            {
                throw new Exception("Interface based message are not supported. Create a class that implements the desired interface.");
            }


            var handle = messageType.TypeHandle;

            if (emptyTypesBag.ContainsKey(handle))
            {
                return;
            }
            MsgPack.Serialization.MessagePackSerializer serializer;
            try
            {
                serializer = context.GetSerializer(messageType);
            }
            catch (SerializationException exception)
                when(IsEmptyTypeException(exception))
                {
                    stream.WriteByte(0);
                    emptyTypesBag[handle] = ConstructorDelegateBuilder.BuildConstructorFunc(messageType);
                    return;
                }
            serializer.Pack(stream, message);
        }