Protocol Buffer over socket in C++

后端 未结 2 1329
感动是毒
感动是毒 2020-12-07 16:41

I am trying to explore Protocol Buffer (PB) in Linux platform and my coding language is C++. I found examples in the protocol buffer online docs but nothing specific to sock

2条回答
  •  情话喂你
    2020-12-07 17:26

    Unfortunately, protobuf does not provide a way for "packaging" (delimiting) your messages:

    If you want to write multiple messages to a single file or stream, it is up to you to keep track of where one message ends and the next begins. The Protocol Buffer wire format is not self-delimiting, so protocol buffer parsers cannot determine where a message ends on their own. The easiest way to solve this problem is to write the size of each message before you write the message itself.

    (from their documentation)

    So, they basically recommend the same solution you arrived at.

提交回复
热议问题