aakash-sahai / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

Api similar to xxxxx__get_packed_size() not availabe #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Before we pack the data, there is no way that we can get the packed-size. 
protobuf-c has xxxxx__get_packed_size() api, which gives the packed-size. Can 
we have similar api in nanopb?
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by feroz.af...@gmail.com on 25 Jun 2012 at 4:47

GoogleCodeExporter commented 9 years ago
Finding the encoded size is essentially the same operation as packing the data, 
also in protobuf-c. Nanopb avoids the duplicated code by using pb_encode also 
to calculate the size.

You can do it like this:

pb_ostream_t substream = {0};
pb_encode(&substream, fields, src_struct);
size = substream.bytes_written;

(http://koti.kapsi.fi/~jpa/nanopb/docs/concepts.html#output-streams  "The 
callback for output stream may be NULL, in which case the stream simply counts 
the number of bytes written.")

Not sure if it is worth it to include a wrapper function to do that.

Original comment by Petteri.Aimonen on 25 Jun 2012 at 4:58

GoogleCodeExporter commented 9 years ago

Original comment by Petteri.Aimonen on 30 Jun 2012 at 3:24

GoogleCodeExporter commented 9 years ago
This issue was updated by revision b63e582bdb34.

Original comment by Petteri.Aimonen on 5 Apr 2014 at 8:33

GoogleCodeExporter commented 9 years ago
Fix released in nanopb-0.2.8

Original comment by Petteri.Aimonen on 7 Apr 2014 at 5:51