diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-06-03 22:46:19 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-06-03 22:46:19 +0300 |
commit | a1cec46b3e824292b4ae22fa1f5c4faf9846196c (patch) | |
tree | 7a9eada9be94db565daf88eeb50204c8ae07d786 /generator/nanopb_generator.py | |
parent | bfd7cb36b90dfa22d37c918d8cdcdce60bc8af85 (diff) |
Include the field tags in the generated .pb.h file.
Patch from Michael Haberler.
Diffstat (limited to 'generator/nanopb_generator.py')
-rw-r--r-- | generator/nanopb_generator.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 3529a346..bd365dfd 100644 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -235,6 +235,11 @@ class Field: else: return 'const %s %s_default%s = %s;' % (ctype, self.struct_name + self.name, array_decl, default) + def tags(self): + '''Return the #define for the tag number of this field.''' + identifier = '%s_%s_tag' % (self.struct_name, self.name) + return '#define %-40s %d\n' % (identifier, self.tag) + def pb_field_t(self, prev_field_name): '''Return the pb_field_t initializer to use in the constant array. prev_field_name is the name of the previous field or None. @@ -490,6 +495,12 @@ def generate_header(dependencies, headername, enums, messages, options): yield msg.default_decl(True) yield '\n' + yield '/* Field tags (for use in manual encoding/decoding) */\n' + for msg in sort_dependencies(messages): + for field in msg.fields: + yield field.tags() + yield '\n' + yield '/* Struct field encoding specification for nanopb */\n' for msg in messages: yield msg.fields_declaration() + '\n' |