diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-07-17 20:21:51 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-07-17 20:21:51 +0300 |
commit | 64947cb382271e2ab17dbf40ab634846d7d30ad9 (patch) | |
tree | c8ca363f421f5103d625fca51f085cb93330dd15 /generator | |
parent | 0343e2bcfe97748e8b1b93ecacb2e72fc0be7453 (diff) |
Extension support implemented for decoder.
Testing is still needed. Also only 'optional' extension fields
are supported now, 'repeated' fields are not yet supported.
Diffstat (limited to 'generator')
-rw-r--r-- | generator/nanopb_generator.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 61f4d7b3..3bac9a92 100644 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -276,9 +276,13 @@ class Field: class ExtensionRange(Field): - def __init__(self, struct_name, desc, field_options): - '''desc is ExtensionRange''' - self.tag = desc.start + def __init__(self, struct_name, range_start, field_options): + '''Implements a special pb_extension_t* field in an extensible message + structure. The range_start signifies the index at which the extensions + start. Not necessarily all tags above this are extensions, it is merely + a speed optimization. + ''' + self.tag = range_start self.struct_name = struct_name self.name = 'extensions' self.pbtype = 'EXTENSION' @@ -304,6 +308,10 @@ class ExtensionField(Field): self.fullname = struct_name + desc.name self.extendee_name = names_from_type_name(desc.extendee) 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)) def extension_decl(self): '''Declaration of the extension type in the .pb.h file''' @@ -341,8 +349,9 @@ class Message: if len(desc.extension_range) > 0: field_options = get_nanopb_suboptions(desc, message_options, self.name + 'extensions') + range_start = min([r.start for r in desc.extension_range]) if field_options.type != nanopb_pb2.FT_IGNORE: - self.fields.append(ExtensionRange(self.name, desc.extension_range[0], field_options)) + self.fields.append(ExtensionRange(self.name, range_start, field_options)) self.packed = message_options.packed_struct self.ordered_fields = self.fields[:] |