Class: ProtobufDescriptor::MessageDescriptor::FieldDescriptor

Inherits:
Object
  • Object
show all
Includes:
HasParent
Defined in:
lib/protobuf_descriptor/message_descriptor.rb

Overview

Describes a field within a message.

See FieldDescriptorProto

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasParent

#file_descriptor, #protobuf_descriptor

Constructor Details

#initialize(parent, field_descriptor_proto) ⇒ FieldDescriptor

Returns a new instance of FieldDescriptor.



23
24
25
26
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 23

def initialize(parent, field_descriptor_proto)
  @parent = parent
  @field_descriptor_proto = field_descriptor_proto
end

Instance Attribute Details

#field_descriptor_protoObject (readonly)

The FieldDescriptorProto this FieldDescriptor is wrapping.



21
22
23
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 21

def field_descriptor_proto
  @field_descriptor_proto
end

#parentObject (readonly)

The parent MessageDescriptor



19
20
21
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 19

def parent
  @parent
end

Instance Method Details

#default_valueObject

Default value for this field.

  • For numeric types, contains the original text representation of the value.

  • For booleans, “true” or “false”.

  • For strings, contains the default text contents (not escaped in any way).

  • For bytes, contains the C escaped value. All bytes >= 128 are escaped.



41
42
43
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 41

def default_value
  field_descriptor_proto.default_value
end

#extendeeObject

For extensions, this is the name of the type being extended. It is resolved in the same manner as type_name.



47
48
49
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 47

def extendee
  field_descriptor_proto.extendee
end

#field_typeObject

If type_name is set, this need not be set. If both this and type_name are set, this must be either TYPE_ENUM or TYPE_MESSAGE.



81
82
83
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 81

def field_type
  field_descriptor_proto.type
end

#labelObject

Whether the field is optional/required/repeated.



63
64
65
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 63

def label
  field_descriptor_proto.label
end

#nameObject

The name of this field.



73
74
75
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 73

def name
  field_descriptor_proto.name
end

#numberObject

The tag number of this field.



68
69
70
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 68

def number
  field_descriptor_proto.number
end

#optionsObject

The FieldOptions for this field



29
30
31
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 29

def options
  field_descriptor_proto.options
end

#resolve_typeObject

Resolves the field’s type_name, returning the MessageDescriptor or EnumDescriptor that this field will represent.



88
89
90
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 88

def resolve_type
  protobuf_descriptor.resolve_type_name(self.type_name, self.parent)
end

#type_nameObject

For message and enum types, this is the name of the type. If the name starts with a ‘.’, it is fully-qualified. Otherwise, C++-like scoping rules are used to find the type (i.e. first the nested types within this message are searched, then within the parent, on up to the root namespace).

Note: the protocol buffer compiler always emits the fully qualified name!



58
59
60
# File 'lib/protobuf_descriptor/message_descriptor.rb', line 58

def type_name
  field_descriptor_proto.type_name
end