atom feed10 messages in com.googlegroups.protobufRe: Serialize with Length Prefix
FromSent OnAttachments
Jay ThomasAug 24, 2009 3:54 pm 
Peter KeenAug 24, 2009 4:05 pm 
Jay ThomasAug 24, 2009 4:07 pm 
Jay ThomasAug 24, 2009 4:17 pm 
Peter KeenAug 24, 2009 4:24 pm 
Peter KeenAug 24, 2009 4:33 pm 
Jay ThomasAug 24, 2009 4:42 pm 
Marc GravellAug 25, 2009 12:07 am 
Paul ShaferFeb 20, 2013 1:32 pm 
Marc GravellFeb 20, 2013 8:57 pm 
Subject:Re: Serialize with Length Prefix
From:Peter Keen (
Date:Aug 24, 2009 4:05:38 pm

You sort of have to roll your own. In my project I'm doing something like this:

coded_output->WriteVarint32(message->ByteSize()); message->SerializeToCodedStream(coded_output);

And then on the reading side:

uint32_t size; if (! coded_input->ReadVarint32(&size)) { return NULL; // just an example. probably don't want to do this; }

Message * m = new Message; CodedInputStream::Limit limit = coded_input->PushLimit(size); message->ParseFromCodedStream(coded_input); coded_input->PopLimit(limit);

The biggest thing that helped me along was finding the Limit docs. I couldn't figure out how to parse from a ZeroCopyInputStream without consuming the entire stream, and then I ran across that and everything became much more clear.


On Mon, Aug 24, 2009 at 3:54 PM, Jay Thomas<> wrote:


I am looking for a way to serialize/deserialize with length prefix under c++.  The serialized bytes will sent to a TCP socket.  I am aware that C# has a method SerializeWithLengthPrefix() and DeserializeWithLengthPrefix().  Are there any such analogous methods for C++? Please point out any documentation that I may have missed here.

Thanks for any assistance.