My (DSP) application produces data at a constant rate. The rate depends on the configuration that is selected by the user. I would like to know how many bytes are generated per second. The data structure contains a repeated (packed) floating point field. The length of the field is constant, but can be changed by the user.
Is there a protocol buffers function that will calculate the message size before serialization?
It’s impossible to know ahead of time, because protobuf packs the structures it is given into the fewest bytes possible – it won’t use four bytes for
int x = 1;for example – so the library would have to walk the entire graph to know the output size.I believe you could find this out by doing a serialize operation to a protobuf-compliant stream of your own design that just counts the bytes it is given. That could be costly, but no more costly than it would be for the library to do that work.