class ProtobufDescriptor::FieldDescriptor

Describes a field within a message.

See FieldDescriptorProto

Attributes

field_descriptor_proto[R]

The FieldDescriptorProto this FieldDescriptor is wrapping.

parent[R]

The parent {ProtobufDescriptor::MessageDescriptor}

Public Class Methods

new(parent, field_descriptor_proto) click to toggle source
# File lib/protobuf_descriptor/field_descriptor.rb, line 13
def initialize(parent, field_descriptor_proto)
  @parent = parent
  @field_descriptor_proto = field_descriptor_proto
end

Public Instance Methods

default_value() click to toggle source

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.

# File lib/protobuf_descriptor/field_descriptor.rb, line 31
def default_value
  field_descriptor_proto.default_value
end
extendee() click to toggle source

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

# File lib/protobuf_descriptor/field_descriptor.rb, line 37
def extendee
  field_descriptor_proto.extendee
end
field_type() click to toggle source

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.

# File lib/protobuf_descriptor/field_descriptor.rb, line 69
def field_type
  field_descriptor_proto.type
end
label() click to toggle source

Whether the field is optional/required/repeated.

# File lib/protobuf_descriptor/field_descriptor.rb, line 53
def label
  field_descriptor_proto.label
end
name() click to toggle source

The name of this field.

# File lib/protobuf_descriptor/field_descriptor.rb, line 63
def name
  field_descriptor_proto.name
end
number() click to toggle source

The tag number of this field.

# File lib/protobuf_descriptor/field_descriptor.rb, line 58
def number
  field_descriptor_proto.number
end
options() click to toggle source

The FieldOptions for this field

# File lib/protobuf_descriptor/field_descriptor.rb, line 19
def options
  field_descriptor_proto.options
end
resolve_type() click to toggle source

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

# File lib/protobuf_descriptor/field_descriptor.rb, line 76
def resolve_type
  protobuf_descriptor.resolve_type_name(self.type_name, self.parent)
end
type_name() click to toggle source

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!

# File lib/protobuf_descriptor/field_descriptor.rb, line 48
def type_name
  field_descriptor_proto.type_name
end