Search code examples
network-programmingerror-handlingprotocol-buffersblockingnonblocking

Does protocol buffer handle nicely end of data on stream


I am totally newbie in c#, .net core 2 and protocol buffers but I have to work with thoses 3 technologies for a personnel project (server/client architecture). I have some questions about serialization/deserialization in multiple message. I have already see this: https://developers.google.com/protocol-buffers/docs/techniques#streaming So I know it's need a special technique. After a little google session I found something about put and pop limits in c++ but I haven't see docs on c#.

I have an another question, does google protocol buffers handle nicely reading ? My sockets are monitored with select so when I want to read my messages (using https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/message-parser#class_google_1_1_protobuf_1_1_message_parser_1a110e5d9bc61837e369e5deb093f59161) I am not sure how protobuf will stop reading (I don't want to read beyond the data available on the socket because it will make my server blocking...) Does it manage it ? Thank you...


Solution

  • Standalone protobufs aren't delimited in any way - they don't encode their length and have no fixed start nor end.

    But the API gives you some tools for sending and storing multiple messages - specifically, you can use WriteDelimitedTo() to write multiple protobufs to some output, and then read them using parseDelimitedFrom()