I have repeating messages which I want to store in a single file. Currently I have to wrap this repeating message in another message. Is there a way around this?
package foo;
message Box {
required int32 tl_x = 1;
required int32 tl_y = 2;
required int32 w = 3;
required int32 h = 4;
}
message Boxes {
repeated Box boxes = 1;
}
In java you can use delimited messages. For C++ see Are there C++ equivalents for the Protocol Buffers delimited I/O functions in Java?
Basically in C++ according to above
and python you would need to work it out
Here's what "Techniques" section of the Protocol Buffers documentation says about repeated messages:
There's also a conventional way of implementing this in C++ and Java. Take a look at this Stack Overflow thread for details: Are there C++ equivalents for the Protocol Buffers delimited I/O functions in Java?
Protobuf doesn't support this functionality. It can be used to just serialize one message, but this serialized message doesn't contain information about its type (Box or Boxes) and length. So if you want to store multiple message you have to include type and length of message as well. Writing algorithm (in pseudo language) could look like this:
Load algorithm: