aakash-sahai / nanopb

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

Make required field checking work for fields > 32 #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently pb_decode() only detects missing required fields for messages of less 
than 32 fields.

There are many ways to implement this; dynamic-alloc branch uses a bitfield 
stored in the message structure, but that requires somewhat ugly macros for 
handling the bitfield.

Instead, a less intrusive implementation plan:

1) Add required_field_index to pb_field_iterator_t. Increment it for every 
required field. Use it to set bit in fields_seen just for PB_HTYPE_REQUIRED 
fields.

2) Add a new compile-time option PB_MAX_REQUIRED_FIELDS, with default value 32.

3) Make the fields_seen bitfield in pb_decode as uint8_t 
fields_seen[PB_MAX_REQUIRED_FIELDS / 8].

4) Make the generator generate code that checks for sufficient limit:
#if PB_MAX_REQUIRED_FIELDS < 45
#warning Message FooBarMessage requires PB_MAX_REQUIRED_FIELDS >= 45 to 
properly check for missing required fields.
#endif

Thanks to Greg Klein for report and help in designing the fix.

Original issue reported on code.google.com by Petteri.Aimonen on 29 Jun 2012 at 6:09

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 95eb4a549981.

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