I agree, and it seems to be a question that comes up frequently in this forum, so maybe we should add a page to the Wiki that discusses how to send and receive a stream of protobuf (or any) messages. Things like run length encoding, magic bytes, checksums, record types - these are either highly desirable or absolutely necessary when streaming blocks of opaque binary data over a network connection, reading a sequence of them from a file, or whatever. I think there may be a misconception out there that libprotobuf somehow magically takes care of all those things. It seems to me that people need to conceive of a serialized protobuf object as the payload to a packet, and it is their job to design a packet header that describes the payload with sufficient information such that it can be extracted and dispatched to the appropriate handler.
-dave On Jan 12, 5:32 pm, Stuart Johnson <[email protected]> wrote: > It's a good idea to send a delimiter as well, even if your end-to-end > communication is considered reliable (TCP). A software bug at ether end > could cause you to loose sync. > > Use one byte as your "Start Byte" (0xaa for example) followed by the > length of your message (can be a compressed integer). When you receive > a message, look for the Start byte (which should always be the first > byte), decode the length, and then verify that you have all the bytes > you need to decode the rest of the data. Before you decode, verify that > you have reached the end of the stream or that the next byte is the > start of the next message. > > Kenton Varda wrote: > > Send the size of the message first, then the data. > > > On Mon, Jan 12, 2009 at 4:34 PM, chongyc <[email protected] > > <mailto:[email protected]>> wrote: > > > When I send multiple messages, I should delimit them, and parse the > > buffer. > > > What is the best way delimitting it that you can recommend me ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~----------~----~----~----~------~----~------~--~---
