public BufferSession Serialize(Commit model)
        {
            var wire = model.Convert();

            var maxLen = Encoding.UTF8.GetMaxByteCount(wire.Length); // Utf8 is 1-4 bpc
            var rented = BufferSession.RentBuffer(maxLen);

            var count = Encoding.UTF8.GetBytes(wire, 0, wire.Length, rented, 0);

            var seg     = new ArraySegment <byte>(rented, 0, count);
            var session = new BufferSession(seg);

            return(session);
        }
Exemplo n.º 2
0
        public BufferSession Serialize(Commit model)
        {
            var wire = model.Convert();

            var size   = wire.CalculateSize();
            var buffer = BufferSession.RentBuffer(size);

            using (var cos = new CodedOutputStream(buffer))
            {
                wire.WriteTo(cos);

                var segment = new ArraySegment <byte>(buffer, 0, (int)cos.Position);

                var session = new BufferSession(buffer, segment);
                return(session);
            }
        }