Ejemplo n.º 1
0
        private object DeserializeImpl(Stream stream)
        {
            MessagePackage package = ProtoBuf.Serializer.Deserialize <MessagePackage>(stream);

            MemoryStream messageBuf = new MemoryStream(package.message);

            return(deserializeTable[new MessageTypeID()
                                    {
                                        CategoryID = package.category_id, TypeID = package.type_id
                                    }](messageBuf));
        }
Ejemplo n.º 2
0
        public void Serialize <T>(T message, Stream dest) where T : class
        {
            Debug.Assert(ProtoBuf.Serializer.NonGeneric.CanSerialize(message.GetType()));

            MemoryStream messageBuf = new MemoryStream();

            SerializeImpl(messageBuf, message);

            var            messageType = messageTypeTable[message.GetType()];
            MessagePackage package     = new MessagePackage();

            package.category_id = messageType.CategoryID;
            package.type_id     = messageType.TypeID;
            package.message     = messageBuf.ToArray();

            SerializeImpl(dest, package);
        }