we plan to use protobuf for our project passing sensor data from micro controllers to Linux based system. Therefore we want to use the variety of languages. Now I implemented examples in all three of them doing exactly the same. The message structure is like this:
Sensors{
required Time time =1;
repeated Imu imu= 2;
optional Temperature temperature= 3;
.
.
.(all others optional)
}
Time{
optional Ticks ticks =1;
optional Timestamp utc =2;
.
.
.
}
Ticks{
required uint32 ticks =1;
}
Time{
optional uint64 secs =1;
optional uint64 nsecs =2;
}
In the example I just get the UTC timestamp and set the uint64 values correspondingly. Then I serialize the message and decode it at the end. For all languages (python, nanopb, c++) the results of the decoded message fit the encoded one, but the size of the decoded stream varies a lot.
C++: ByteSize() returns 15 to 16 bytes depending on the run.
NanoPB: bytes_written returns 300 to 308 bytes depending on the run.
Python: len() returns 15 to 16 bytes
sys.getsizeof() returns 52 to 53 bytes
Can somebody explain me the discrepancy in size between c++ and nanopb?
It is quiet important to us since we do knot want to transmit to much overhead via the serial port.
Thanks for your time.
Fabian
Well that did the trick. Thanks a lot.
Maybe you can add the initializing call also to the simple example.
I understand now of course why it is not necessary there but I think it would help users to not miss it with more complex structures. Or at least a comment about that.
But thanks a lot for the fast help.
Fabian