Class: Protobuf::Enum

Inherits:
Object
  • Object
show all
Extended by:
Protoable
Defined in:
lib/protobuf/message/enum.rb

Direct Known Subclasses

Google::Protobuf::FieldDescriptorProto::Label, Google::Protobuf::FieldDescriptorProto::Type, Google::Protobuf::FieldOptions::CType, Google::Protobuf::FileOptions::OptimizeMode

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Methods included from Protoable

defined_filenames, defined_in, proto_contents, proto_filenames, retrieve_header

Class Attribute Details

+ (Object) values (readonly)

Returns the value of attribute values



11
12
13
# File 'lib/protobuf/message/enum.rb', line 11

def values
  @values
end

Class Method Details

+ (Object) descriptor



28
29
30
# File 'lib/protobuf/message/enum.rb', line 28

def descriptor
  @descriptor ||= Descriptor::EnumDescriptor.new(self)
end

+ (Object) name_by_value(value) Also known as: get_name_by_tag



13
14
15
16
17
18
19
20
# File 'lib/protobuf/message/enum.rb', line 13

def name_by_value(value)
  if not defined?(@values)
    constants.find {|c| const_get(c) == value}  # for compatibility
  else
    @values_index ||= @values.inject({}) {|hash, (n, v)| hash[v.value.to_i] = n; hash }
    @values_index[value]
  end
end

+ (Boolean) valid_tag?(tag)

Returns:

  • (Boolean)


24
25
26
# File 'lib/protobuf/message/enum.rb', line 24

def valid_tag?(tag)
  !! name_by_value(tag)
end