protocol buffers - Should I use a binary or a text file for storing protobuf messages? -


Using Google protobuf, I am saving my sorted messages in a file - there are many messages in each file. I have the code of C ++ and Python versions, so I need to use the protocol function that Available in both languages I have experimented with using SerializeToArray and SerializeAsString and here are the following unfortunate conditions:

  1. Serialize Other: As one answer suggests, the best way to use it The way to prefix each message, with its data size, it will work very well for C ++, but this does not look like Python - am I wrong?

  2. SerialistString: This creates a serial string equal to the binary equivalent - which I can save in a file, but what happens if the serialization result is one of the characters \ n - How do we find the end of the line, or the closing of the messages for that matter?

Update:

Please refresh me a bit. As I understand it, I can not write binary data in C ++ because since then our Python can not read application data, since it can only parse stringed serialized messages. Should I use SerializeAsString in both C ++ and Python instead? If so, is it the best practice to store such a data in a text file instead of a binary file? My intestine sense is binary, but as you can see it does not seem to be an option.

The best practice to add messages in this way is to fill each message with its size In this way you read in size (try 32 bit int or anything else), then read the number of those bytes in the buffer, horizontally, then read the next size, etc.

The same goes for writing, you first write the size of the message, then the message itself.

See on Protobf documentation for more information.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -