Class: Protobuf::Field::EnumField

Inherits:
VarintField show all
Defined in:
lib/protobuf/field/enum_field.rb

Constant Summary

Constants inherited from VarintField

VarintField::INT32_MAX, VarintField::INT32_MIN, VarintField::INT64_MAX, VarintField::INT64_MIN, VarintField::UINT32_MAX, VarintField::UINT64_MAX

Constants inherited from BaseField

BaseField::PACKED_TYPES

Instance Attribute Summary

Attributes inherited from BaseField

#message_class, #name, #options, #rule, #tag, #type_class

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VarintField

encode, #wire_type

Methods inherited from BaseField

#coerce!, #default, #default_value, #deprecated?, #extension?, #getter, #initialize, #message?, #optional?, #packed?, #repeated?, #repeated_message?, #required?, #set, #setter, #to_s, #type, #warn_if_deprecated, #wire_type

Methods included from Logging

initialize_logger, #log_exception, #log_signature, #logger, logger, logger=, #sign_message

Constructor Details

This class inherits a constructor from Protobuf::Field::BaseField

Class Method Details

.defaultObject

Class Methods

Raises:

  • (NoMethodError)


11
12
13
# File 'lib/protobuf/field/enum_field.rb', line 11

def self.default
  raise NoMethodError, "#{self}.#{__method__} must be called on an instance"
end

Instance Method Details

#acceptable?(val) ⇒ Boolean

Public Instance Methods

Returns:

  • (Boolean)


19
20
21
# File 'lib/protobuf/field/enum_field.rb', line 19

def acceptable?(val)
  ! type_class.fetch(val).nil?
end

#decode(value) ⇒ Object



27
28
29
30
31
# File 'lib/protobuf/field/enum_field.rb', line 27

def decode(value)
  if acceptable?(value)
    value
  end
end

#encode(value) ⇒ Object



23
24
25
# File 'lib/protobuf/field/enum_field.rb', line 23

def encode(value)
  super(value.to_i)
end

#enum?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/protobuf/field/enum_field.rb', line 33

def enum?
  true
end