diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2012-10-29 18:55:49 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2012-10-29 18:55:49 +0200 |
commit | db1eefc24bd9d1181dee35683c5fe12329f7d969 (patch) | |
tree | cc38ed9ba2fe8ca9b63b1ca9c9077bd9658a0245 /generator/nanopb_generator.py | |
parent | 0ee4bb96b1e53d16a29869864eff87c8934894ae (diff) |
Add option to use short names for enum values.
Update issue 38
Status: FixedInGit
Diffstat (limited to 'generator/nanopb_generator.py')
-rw-r--r-- | generator/nanopb_generator.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 860f3742..2267238c 100644 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -81,7 +81,12 @@ def names_from_type_name(type_name): class Enum: def __init__(self, names, desc, enum_options): '''desc is EnumDescriptorProto''' - self.names = names + desc.name + + if enum_options.long_names: + self.names = names + desc.name + else: + self.names = names + self.values = [(self.names + x.name, x.number) for x in desc.value] def __str__(self): @@ -376,7 +381,8 @@ def parse_file(fdesc, file_options): base_name = Names() for enum in fdesc.enum_type: - enums.append(Enum(base_name, enum, file_options)) + enum_options = get_nanopb_suboptions(enum, file_options) + enums.append(Enum(base_name, enum, enum_options)) for names, message in iterate_messages(fdesc, base_name): message_options = get_nanopb_suboptions(message, file_options) @@ -548,6 +554,8 @@ def get_nanopb_suboptions(subdesc, options): ext_type = nanopb_pb2.nanopb_fileopt elif isinstance(subdesc.options, descriptor.MessageOptions): ext_type = nanopb_pb2.nanopb_msgopt + elif isinstance(subdesc.options, descriptor.EnumOptions): + ext_type = nanopb_pb2.nanopb_enumopt else: raise Exception("Unknown options type") |