Reputation: 283
I am currently writing the java code to check the number of messages in a protocol buffer file *.pb
I would like to know if there is meta-data or header that contains the information of number of messages in the protobuf file? I am looping through the whole file, and I think there should be a better way to do it.
while ((m = message.getParserForType().parseDelimitedFrom(input)) != null) {
recordCount++;
}
Thanks David
Upvotes: 0
Views: 383
Reputation: 1476
There is no header or anything that will tell you the number of messages in the file. That format just consists of a length prefix in varint format, followed by a message payload, repeated for as many messages as you have.
However, you could in principle count the number of messages in a much more efficient way. If you just want to know how many there are, you could read the length prefixes and skip over the actual message payloads without parsing them.
Upvotes: 1