From d2c1604d6d239cdab6b21f3daf6634eb112ae318 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Thu, 10 Jan 2013 17:32:27 +0200 Subject: 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 --- generator/nanopb_generator.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'generator/nanopb_generator.py') 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): -- cgit 1.2.3-korg