aboutsummaryrefslogtreecommitdiffstats
path: root/generator/nanopb_generator.py
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-01-10 17:32:27 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-01-10 17:32:27 +0200
commitd2c1604d6d239cdab6b21f3daf6634eb112ae318 (patch)
treeb17e5aabb6d06f1cf7780ffb856016e86c7d3a67 /generator/nanopb_generator.py
parent93ffe14a0ae32eeda8275f48106e76ecc650168d (diff)
Add generator option for packed structs.
Usage is: message Foo { option (nanopb_msgopt).packed_struct = true; ... } Valid also in file scope. Update issue 49 Status: FixedInGit
Diffstat (limited to 'generator/nanopb_generator.py')
-rw-r--r--generator/nanopb_generator.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index bffdb353..a583b3f6 100644
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -307,6 +307,7 @@ class Message:
def __init__(self, names, desc, message_options):
self.name = names
self.fields = [Field(self.name, f, get_nanopb_suboptions(f, message_options)) for f in desc.field]
+ self.packed = message_options.packed_struct
self.ordered_fields = self.fields[:]
self.ordered_fields.sort()
@@ -317,7 +318,12 @@ class Message:
def __str__(self):
result = 'typedef struct _%s {\n' % self.name
result += '\n'.join([str(f) for f in self.ordered_fields])
- result += '\n} %s;' % self.name
+ result += '\n}'
+
+ if self.packed:
+ result += ' pb_packed'
+
+ result += ' %s;' % self.name
return result
def types(self):