summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-06-30 18:23:18 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-06-30 18:23:18 +0300
commit67add3259a6429cb4afc1bdb6345e8c057a55ca8 (patch)
treea9c6938a9bec1528d8f8a0c029e2dd219487f9a3 /generator
parent95eb4a549981dc556dd30c5d76a6b437bb5ed06d (diff)
Warn if PB_MAX_REQUIRED_FIELDS is not large enough.
Diffstat (limited to 'generator')
-rw-r--r--generator/nanopb_generator.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 1e7e1f98..730c0aab 100644
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -402,6 +402,16 @@ def generate_header(dependencies, headername, enums, messages):
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'
+
yield '\n#endif\n'
def generate_source(headername, enums, messages):