+class ExtensionField(Field):
+ def __init__(self, struct_name, desc, field_options):
+ 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))
+
+ self.rules = 'OPTEXT'
+
+ def extension_decl(self):
+ '''Declaration of the extension type in the .pb.h file'''
+ 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'''
+
+ result = 'typedef struct {\n'
+ result += str(self)
+ result += '\n} %s;\n\n' % self.struct_name
+ result += ('static const pb_field_t %s_field = \n %s;\n\n' %
+ (self.fullname, self.pb_field_t(None)))
+ result += 'const pb_extension_type_t %s = {\n' % self.fullname
+ result += ' NULL,\n'
+ result += ' NULL,\n'
+ result += ' &%s_field\n' % self.fullname
+ result += '};\n'
+ return result