Class: ProtobufDescriptor::FieldDescriptor
- Inherits:
-
Object
- Object
- ProtobufDescriptor::FieldDescriptor
- Includes:
- HasParent
- Defined in:
- lib/protobuf_descriptor/field_descriptor.rb
Overview
Describes a field within a message.
See FieldDescriptorProto[https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto#103]
Instance Attribute Summary collapse
-
#field_descriptor_proto ⇒ Object
readonly
The +FieldDescriptorProto+ this +FieldDescriptor+ is wrapping.
-
#parent ⇒ Object
readonly
The parent MessageDescriptor.
Instance Method Summary collapse
-
#default_value ⇒ Object
Default value for this field.
-
#extendee ⇒ Object
For extensions, this is the name of the type being extended.
-
#field_type ⇒ Object
If type_name is set, this need not be set.
-
#initialize(parent, field_descriptor_proto) ⇒ FieldDescriptor
constructor
A new instance of FieldDescriptor.
-
#label ⇒ Object
Whether the field is optional/required/repeated.
-
#name ⇒ Object
The name of this field.
-
#number ⇒ Object
The tag number of this field.
-
#options ⇒ Object
The +FieldOptions+ for this field.
-
#resolve_type ⇒ Object
Resolves the field's +type_name+, returning the MessageDescriptor or EnumDescriptor that this field will represent.
-
#type_name ⇒ Object
For message and enum types, this is the name of the type.
Methods included from HasParent
#compute_source_code_info_path, #file_descriptor, #leading_comments, #protobuf_descriptor, #source_code_info_location, #source_code_info_locations, #source_code_info_span, #trailing_comments
Constructor Details
#initialize(parent, field_descriptor_proto) ⇒ FieldDescriptor
Returns a new instance of FieldDescriptor.
13 14 15 16 |
# File 'lib/protobuf_descriptor/field_descriptor.rb', line 13 def initialize(parent, field_descriptor_proto) @parent = parent @field_descriptor_proto = field_descriptor_proto end |
Instance Attribute Details
#field_descriptor_proto ⇒ Object (readonly)
The +FieldDescriptorProto+ this +FieldDescriptor+ is wrapping.
11 12 13 |
# File 'lib/protobuf_descriptor/field_descriptor.rb', line 11 def field_descriptor_proto @field_descriptor_proto end |
#parent ⇒ Object (readonly)
The parent MessageDescriptor
9 10 11 |
# File 'lib/protobuf_descriptor/field_descriptor.rb', line 9 def parent @parent end |
Instance Method Details
#default_value ⇒ Object
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.
31 32 33 |
# File 'lib/protobuf_descriptor/field_descriptor.rb', line 31 def default_value field_descriptor_proto.default_value end |
#extendee ⇒ Object
For extensions, this is the name of the type being extended. It is resolved in the same manner as type_name.
37 38 39 |
# File 'lib/protobuf_descriptor/field_descriptor.rb', line 37 def extendee field_descriptor_proto.extendee end |
#field_type ⇒ Object
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.
69 70 71 |
# File 'lib/protobuf_descriptor/field_descriptor.rb', line 69 def field_type field_descriptor_proto.type end |
#label ⇒ Object
Whether the field is optional/required/repeated.
53 54 55 |
# File 'lib/protobuf_descriptor/field_descriptor.rb', line 53 def label field_descriptor_proto.label end |
#name ⇒ Object
The name of this field.
63 64 65 |
# File 'lib/protobuf_descriptor/field_descriptor.rb', line 63 def name field_descriptor_proto.name end |
#number ⇒ Object
The tag number of this field.
58 59 60 |
# File 'lib/protobuf_descriptor/field_descriptor.rb', line 58 def number field_descriptor_proto.number end |
#options ⇒ Object
The +FieldOptions+ for this field
19 20 21 |
# File 'lib/protobuf_descriptor/field_descriptor.rb', line 19 def field_descriptor_proto. end |
#resolve_type ⇒ Object
Resolves the field's +type_name+, returning the MessageDescriptor or EnumDescriptor that this field will represent.
76 77 78 |
# 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 ⇒ Object
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!
48 49 50 |
# File 'lib/protobuf_descriptor/field_descriptor.rb', line 48 def type_name field_descriptor_proto.type_name end |