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
Original issue reported on code.google.com by
Petteri.Aimonen
on 29 Jun 2012 at 6:09