From d7f3a74388b4825d2c980c53d0a740ddfd0e4770 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Sun, 8 Sep 2013 11:05:20 +0300 Subject: Handle unsupported extension field types more gracefully. Previously the generator would stop with NotImplementedException as soon as a required or repeated extension field is found. New behaviour is to just ignore the unsupported field and note that in a comment in the generated file. Furthermore, allow skipping of extension fields using the generator option (nanopb).type = FT_IGNORE. Update issue 83 Status: FixedInGit --- generator/nanopb_generator.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'generator/nanopb_generator.py') diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index e3cddb61..55e5ab65 100644 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -310,18 +310,26 @@ class ExtensionField(Field): Field.__init__(self, self.fullname + 'struct', desc, field_options) if self.rules != 'OPTIONAL': - raise NotImplementedError("Only 'optional' is supported for extension fields. " - + "(%s.rules == %s)" % (self.fullname, self.rules)) - - self.rules = 'OPTEXT' + self.skip = True + else: + self.skip = False + self.rules = 'OPTEXT' def extension_decl(self): '''Declaration of the extension type in the .pb.h file''' + if self.skip: + msg = '/* Extension field %s was skipped because only "optional"\n' % self.fullname + msg +=' type of extension fields is currently supported. */\n' + return msg + return 'extern const pb_extension_type_t %s;\n' % self.fullname def extension_def(self): '''Definition of the extension type in the .pb.c file''' + if self.skip: + return '' + result = 'typedef struct {\n' result += str(self) result += '\n} %s;\n\n' % self.struct_name @@ -475,7 +483,8 @@ def parse_file(fdesc, file_options): for names, extension in iterate_extensions(fdesc, base_name): field_options = get_nanopb_suboptions(extension, file_options, names) - extensions.append(ExtensionField(names, extension, field_options)) + if field_options.type != nanopb_pb2.FT_IGNORE: + extensions.append(ExtensionField(names, extension, field_options)) # Fix field default values where enum short names are used. for enum in enums: -- cgit 1.2.3-korg