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
This commit is contained in:
Petteri Aimonen
2013-01-10 17:32:27 +02:00
parent 93ffe14a0a
commit d2c1604d6d
5 changed files with 31 additions and 6 deletions

View File

@@ -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):