aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generator/nanopb_generator.py46
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'
# ---------------------------------------------------------------------------