prev_field_name is the name of the previous field or None.
'''
result = ' {%d, ' % self.tag
- result += self.htype
+ result += '(pb_type_t) ((int) ' + self.htype
if self.ltype is not None:
- result += ' | ' + self.ltype
- result += ',\n'
+ result += ' | (int) ' + self.ltype
+ result += '),\n'
if prev_field_name is None:
result += ' offsetof(%s, %s),' % (self.struct_name, self.name)
for msg in messages:
yield msg.fields_declaration() + '\n'
- 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'
+ if messages:
+ 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 '#error 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 = 0
worst_field = ''
if worst > 255 or checks:
yield '\n/* Check that field information fits in pb_field_t */\n'
- yield '/* (Largest message has %d fields' % worst
- if checks: yield ' and submessages have to be checked at compile-time.'
- yield ') */\n'
if worst < 65536:
yield '#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT)\n'