예제 #1
0
 def setup(self):
   self.my_file = descriptor.filedescriptor(
       name='some/filename/some.proto',
       package='protobuf_unittest'
       )
   self.my_enum = descriptor.enumdescriptor(
       name='foreignenum',
       full_name='protobuf_unittest.foreignenum',
       filename=none,
       file=self.my_file,
       values=[
         descriptor.enumvaluedescriptor(name='foreign_foo', index=0, number=4),
         descriptor.enumvaluedescriptor(name='foreign_bar', index=1, number=5),
         descriptor.enumvaluedescriptor(name='foreign_baz', index=2, number=6),
       ])
   self.my_message = descriptor.descriptor(
       name='nestedmessage',
       full_name='protobuf_unittest.testalltypes.nestedmessage',
       filename=none,
       file=self.my_file,
       containing_type=none,
       fields=[
         descriptor.fielddescriptor(
           name='bb',
           full_name='protobuf_unittest.testalltypes.nestedmessage.bb',
           index=0, number=1,
           type=5, cpp_type=1, label=1,
           has_default_value=false, default_value=0,
           message_type=none, enum_type=none, containing_type=none,
           is_extension=false, extension_scope=none),
       ],
       nested_types=[],
       enum_types=[
         self.my_enum,
       ],
       extensions=[])
   self.my_method = descriptor.methoddescriptor(
       name='bar',
       full_name='protobuf_unittest.testservice.bar',
       index=0,
       containing_service=none,
       input_type=none,
       output_type=none)
   self.my_service = descriptor.servicedescriptor(
       name='testservicewithoptions',
       full_name='protobuf_unittest.testservicewithoptions',
       file=self.my_file,
       index=0,
       methods=[
           self.my_method
       ])
예제 #2
0
  def _makefielddescriptor(self, field_proto, message_name, index,
                           is_extension=false):
    """creates a field descriptor from a fielddescriptorproto.

    for message and enum type fields, this method will do a look up
    in the pool for the appropriate descriptor for that type. if it
    is unavailable, it will fall back to the _source function to
    create it. if this type is still unavailable, construction will
    fail.

    args:
      field_proto: the proto describing the field.
      message_name: the name of the containing message.
      index: index of the field
      is_extension: indication that this field is for an extension.

    returns:
      an initialized fielddescriptor object
    """

    if message_name:
      full_name = '.'.join((message_name, field_proto.name))
    else:
      full_name = field_proto.name

    return descriptor.fielddescriptor(
        name=field_proto.name,
        full_name=full_name,
        index=index,
        number=field_proto.number,
        type=field_proto.type,
        cpp_type=none,
        message_type=none,
        enum_type=none,
        containing_type=none,
        label=field_proto.label,
        has_default_value=false,
        default_value=none,
        is_extension=is_extension,
        extension_scope=none,
        options=field_proto.options)