Beispiel #1
0
        public static byte[] Serialize <T>(T item) where T : IMessage
        {
            var calcSize = new ProtoSizeCalc(item);
            var result   = new byte[calcSize.Size];
            var stream   = new ProtoOutputStream(calcSize, result);

            item.WriteTo(stream);
            return(result);
        }
Beispiel #2
0
        public static Pooled <ByteBuffer> SerializePooled <T>(T item) where T : IMessage
        {
            var calcSize = new ProtoSizeCalc(item);
            var result   = SerializerBuffers.Get(calcSize.Size);
            var buf      = result.Item;
            var stream   = new ProtoOutputStream(calcSize, buf.Buffer);

            item.WriteTo(stream);
            buf.SetView(0, calcSize.Size);
            return(result);
        }