diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-02-21 19:35:20 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-02-21 19:35:20 +0200 |
commit | 80a2d33fa9a835564b44fe97ba34e713901cf4fb (patch) | |
tree | d611b13f88e737304d96a99c62d847ee798293a5 | |
parent | 41f98343c8e4c94180b514902219044510a234b1 (diff) |
Move STATIC_ASSERTs to .pb.c file.
This way the .pb.h will remain cleaner and easier to read.
-rw-r--r-- | generator/nanopb_generator.py | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 9ecc8f3e..45b2ac68 100644 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -478,6 +478,28 @@ def generate_header(dependencies, headername, enums, messages): for msg in messages: yield msg.fields_declaration() + '\n' + yield '\n#ifdef __cplusplus\n' + yield '} /* extern "C" */\n' + yield '#endif\n' + + # End of header + yield '\n#endif\n' + +def generate_source(headername, enums, messages): + '''Generate content for a source file.''' + + yield '/* Automatically generated nanopb constant definitions */\n' + yield '/* Generated by %s at %s. */\n\n' % (nanopb_version, time.asctime()) + yield '#include "%s"\n\n' % headername + + for msg in messages: + yield msg.default_decl(False) + + yield '\n\n' + + for msg in messages: + yield msg.fields_definition() + '\n\n' + if messages: count_required_fields = lambda m: len([f for f in msg.fields if f.rules == 'REQUIRED']) largest_msg = max(messages, key = count_required_fields) @@ -538,31 +560,11 @@ def generate_header(dependencies, headername, enums, messages): yield '\n' yield '/* On some platforms (such as AVR), double is really float.\n' yield ' * These are not directly supported by nanopb, but see example_avr_double.\n' + yield ' * To get rid of this error, remove any double fields from your .proto.\n' yield ' */\n' yield 'STATIC_ASSERT(sizeof(double) == 8, DOUBLE_MUST_BE_8_BYTES)\n' - yield '\n#ifdef __cplusplus\n' - yield '} /* extern "C" */\n' - yield '#endif\n' - - # End of header - yield '\n#endif\n' - -def generate_source(headername, enums, messages): - '''Generate content for a source file.''' - - yield '/* Automatically generated nanopb constant definitions */\n' - yield '/* Generated by %s at %s. */\n\n' % (nanopb_version, time.asctime()) - yield '#include "%s"\n\n' % headername - - for msg in messages: - yield msg.default_decl(False) - - yield '\n\n' - - for msg in messages: - yield msg.fields_definition() + '\n\n' - + yield '\n' # --------------------------------------------------------------------------- |