+ count_required_fields = lambda m: len([f for f in msg.fields if f.htype == 'PB_HTYPE_REQUIRED'])
+ largest_msg = max(messages, key = count_required_fields)
+ largest_count = count_required_fields(largest_msg)
+ if largest_count > 64:
+ yield '\n/* Check that missing required fields will be properly detected */\n'
+ yield '#if PB_MAX_REQUIRED_FIELDS < %d\n' % largest_count
+ yield '#warning Properly detecting missing required fields in %s requires \\\n' % largest_msg.name
+ yield ' setting PB_MAX_REQUIRED_FIELDS to %d or more.\n' % largest_count
+ yield '#endif\n'
+
+ worst = False
+ worst_field = ''
+ for msg in messages:
+ for field in msg.fields:
+ status = field.needs_32bit_pb_field_t()
+ if status == True:
+ worst = True
+ worst_field = str(field.struct_name) + '.' + str(field.name)
+ elif status != False:
+ if worst == False:
+ worst = status
+ elif worst != True:
+ worst += ' || ' + status
+
+ if worst != False:
+ yield '\n/* Check that field information fits in pb_field_t */\n'
+ yield '#ifndef PB_MANY_FIELDS\n'
+ if worst == True:
+ yield '#error Field descriptor for %s is too large. Define PB_MANY_FIELDS to fix this.\n' % worst_field
+ else:
+ yield 'STATIC_ASSERT(!(%s), YOU_MUST_DEFINE_PB_MANY_FIELDS)\n' % worst
+ yield '#endif\n'
+
+ # End of header