0

I need to write multiple protobuf messages in a file.

I saw the post about the writeDelimitedFrom and parseDelimitedFrom in C++ and was wondering if it's better to use it (or something like it, another style of delimitations) or make a "super message" only containing the message I need to multiply write as a repeated attribute.

syntax = "proto2";
package test;

message myMessage {
  required int32 TimeStamp = 1;
}
message Container {
  repeated myMessage messages = 1;
}

Is it more interesting to write multiple myMessage in a file with read/write DelimitedFrom or one Container with repeated messages ?

I think using read/write DelimitedFrom is more optimized (as I can append only the last message) but using repeated attribute is easier but to SerializeToOstream I think I must pass the whole Container.
I don't think it's possible to serialize only a part of message to append it to the output file as I never saw it, but I can be wrong

Maskim
  • 382
  • 2
  • 4
  • 18

1 Answers1

1

Like you sad both options are possible.

In the case of few myMessages the Container is the easy solution. This because you would not have to write code which picks out the individual messages when reading back the file.

Yes you must pass the whole container. This is where the number of myMessages comes into play. If this is a large number you are probably better of serializing them one myMessage at a time. Appending it to the file and possibly flushing it to the disk.

Bart
  • 1,405
  • 6
  • 32