X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=generator%2Fnanopb_generator.py;h=7b6f0ba951addd6f50fd4b3d865ccf72644582d4;hb=1d249a48ea979729d1b818847dfbea3316cc527e;hp=2f2e853156539ed05659d1358eceb98241a6e0db;hpb=bd22cf27776f8981f1bf2fff4fcccf171a0ed2c8;p=apps%2Fagl-service-can-low-level.git diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 2f2e8531..7b6f0ba9 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -1,7 +1,7 @@ #!/usr/bin/python '''Generate header file for nanopb from a ProtoBuf FileDescriptorSet.''' -nanopb_version = "nanopb-0.2.6-dev" +nanopb_version = "nanopb-0.2.8-dev" import sys @@ -15,6 +15,7 @@ except: try: import google.protobuf.text_format as text_format + import google.protobuf.descriptor_pb2 as descriptor except: sys.stderr.write(''' ************************************************************* @@ -26,7 +27,7 @@ except: try: import proto.nanopb_pb2 as nanopb_pb2 - import proto.descriptor_pb2 as descriptor + import proto.plugin_pb2 as plugin_pb2 except: sys.stderr.write(''' ******************************************************************** @@ -245,7 +246,7 @@ class Field: self.ctype = self.struct_name + self.name + 't' self.enc_size = varint_max_size(self.max_size) + self.max_size elif self.allocation == 'POINTER': - self.ctype = 'pb_bytes_ptr_t' + self.ctype = 'pb_bytes_array_t' elif desc.type == FieldD.TYPE_MESSAGE: self.pbtype = 'MESSAGE' self.ctype = self.submsgname = names_from_type_name(desc.type_name) @@ -265,8 +266,8 @@ class Field: if self.pbtype == 'MESSAGE': # Use struct definition, so recursive submessages are possible result += ' struct _%s *%s;' % (self.ctype, self.name) - elif self.rules == 'REPEATED' and self.pbtype == 'STRING': - # String arrays need to be defined as pointers to pointers + elif self.rules == 'REPEATED' and self.pbtype in ['STRING', 'BYTES']: + # String/bytes arrays need to be defined as pointers to pointers result += ' %s **%s;' % (self.ctype, self.name) else: result += ' %s *%s;' % (self.ctype, self.name) @@ -350,6 +351,8 @@ class Field: result += '0)' elif self.pbtype in ['BYTES', 'STRING'] and self.allocation != 'STATIC': result += '0)' # Arbitrary size default values not implemented + elif self.rules == 'OPTEXT': + result += '0)' # Default value for extensions is not implemented else: result += '&%s_default)' % (self.struct_name + self.name) @@ -1070,7 +1073,6 @@ def main_plugin(): msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) - import proto.plugin_pb2 as plugin_pb2 data = sys.stdin.read() request = plugin_pb2.CodeGeneratorRequest.FromString(data)