class Gapic::Schema::Field
Wrapper for a protobuf Field
.
@!attribute [r] message
@ return [Message | nil] The message if the field is a message, nil otherwise.
@!attribute [r] enum
@ return [Enum | nil] The enum if the field is an enum, nil otherwise.
Attributes
Public Class Methods
Initializes a message object. @param descriptor [Google::Protobuf::FieldDescriptorProto] the
protobuf representation of this service.
@param address [Enumerable<String>] The address of the proto. See
#address for more info.
@param docs [Google::Protobuf::SourceCodeInfo::Location] The docs
of the proto. See #docs for more info.
@param message [Message | nil] The message if the field is a message,
nil otherwise.
@param enum [Enum | nil] The enum if the field is an enum, nil
otherwise.
Gapic::Schema::Proto::new
# File lib/gapic/schema/wrappers.rb, line 620 def initialize descriptor, address, docs, message, enum super descriptor, address, docs @message = message @enum = enum end
Public Instance Methods
Whether this field is an enum. @return [Boolean]
# File lib/gapic/schema/wrappers.rb, line 642 def enum? return true if @enum false end
@return [Array<Google::Api::FieldBehavior>] A designation of a
specific field behavior (required, output only, etc.) in protobuf messages.
# File lib/gapic/schema/wrappers.rb, line 679 def field_behavior return options[:".google.api.field_behavior"] if options [] end
Denotes a field as immutable. This indicates that the field may be set once in a request to create a resource, but may not be changed thereafter.
# File lib/gapic/schema/wrappers.rb, line 726 def immutable? field_behavior.include? Google::Api::FieldBehavior::IMMUTABLE end
Denotes a field as input only. This indicates that the field is provided in requests, and the corresponding field is not included in output.
# File lib/gapic/schema/wrappers.rb, line 719 def input_only? field_behavior.include? Google::Api::FieldBehavior::INPUT_ONLY end
Whether this field is a map @return [Boolean]
# File lib/gapic/schema/wrappers.rb, line 650 def map? return true if repeated? && @message&.map_entry? false end
@return [Field, nil] a key field for this map
or nil if this field is not a map
# File lib/gapic/schema/wrappers.rb, line 658 def map_key_field return nil? unless map? @message.fields.find { |f| f.name == "key" } end
@return [Field, nil] a value field for this map
or nil if this field is not a map
# File lib/gapic/schema/wrappers.rb, line 665 def map_val_field return nil? unless map? @message.fields.find { |f| f.name == "value" } end
Whether this field is a message. @return [Boolean]
# File lib/gapic/schema/wrappers.rb, line 628 def message? return true if @message false end
Denotes a field as a part of oneof. oneof_index is an int field so it'll be 0 by default for every field and an index in the message's oneof table for the oneof fields but since the indexes in the message's oneof table start with 0 as well we need this to determine whether the field is a part of the oneof
# File lib/gapic/schema/wrappers.rb, line 697 def oneof? @descriptor.field? :oneof_index end
Specifically denotes a field as optional. While all fields in protocol buffers are optional, this may be specified for emphasis if appropriate.
# File lib/gapic/schema/wrappers.rb, line 688 def optional? field_behavior.include? Google::Api::FieldBehavior::OPTIONAL end
Denotes a field as output only. This indicates that the field is provided in responses, but including the field in a request does nothing (the server must ignore it and *must not* throw an error as a result of the field's presence).
# File lib/gapic/schema/wrappers.rb, line 712 def output_only? field_behavior.include? Google::Api::FieldBehavior::OUTPUT_ONLY end
Whether this field is a repeated field. @return [Boolean]
# File lib/gapic/schema/wrappers.rb, line 636 def repeated? label == Google::Protobuf::FieldDescriptorProto::Label::LABEL_REPEATED end
Denotes a field as required. This indicates that the field must be provided as part of the request, and failure to do so will cause an error (usually `INVALID_ARGUMENT`).
# File lib/gapic/schema/wrappers.rb, line 704 def required? field_behavior.include? Google::Api::FieldBehavior::REQUIRED end
@return [String] A reference to another resource message or resource
definition. See `google/api/resource.proto`.
# File lib/gapic/schema/wrappers.rb, line 672 def resource_reference options[:".google.api.resource_reference"] if options end