diff options
-rwxr-xr-x | generator/nanopb_generator.py | 8 | ||||
-rw-r--r-- | generator/proto/nanopb.proto | 3 |
2 files changed, 10 insertions, 1 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 8fd45372..aaa0d2f1 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -160,11 +160,17 @@ class Enum: self.values = [(names + x.name, x.number) for x in desc.value] self.value_longnames = [self.names + x.name for x in desc.value] + self.packed = enum_options.packed_enum def __str__(self): result = 'typedef enum _%s {\n' % self.names result += ',\n'.join([" %s = %d" % x for x in self.values]) - result += '\n} %s;' % self.names + result += '\n}' + + if self.packed: + result += ' pb_packed' + + result += ' %s;' % self.names if not self.options.long_names: # Define the long names always so that enum value references diff --git a/generator/proto/nanopb.proto b/generator/proto/nanopb.proto index 3f2ed8e0..b8671bbd 100644 --- a/generator/proto/nanopb.proto +++ b/generator/proto/nanopb.proto @@ -51,6 +51,9 @@ message NanoPBOptions { // accesses to variables. optional bool packed_struct = 5 [default = false]; + // Add 'packed' attribute to generated enums. + optional bool packed_enum = 10 [default = false]; + // Skip this message optional bool skip_message = 6 [default = false]; |