Class: Protobuf::Field::EnumField

Inherits:
VarintField show all
Defined in:
lib/protobuf/message/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

Instance Attribute Summary

Attributes inherited from BaseField

#default, #default_value, #message_class, #name, #rule, #tag, #type

Instance Method Summary collapse

Methods inherited from VarintField

#decode, decode, default, encode, #wire_type

Methods inherited from BaseField

#decode, default, descriptor, #descriptor, #initialize, #initialized?, #max, #merge, #min, #optional?, #packed?, #ready?, #repeated?, #required?, #set, #to_s

Constructor Details

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

Instance Method Details

#acceptable?(val) ⇒ Boolean

Returns:

  • (Boolean)


648
649
650
651
652
653
654
655
656
657
658
# File 'lib/protobuf/message/field.rb', line 648

def acceptable?(val)
  case val
  when Symbol then
    raise TypeError unless @type.const_defined?(val)
  when EnumValue then
    raise TypeError if val.parent_class != @type
  else
    raise TypeError unless @type.valid_tag?(val)
  end
  true
end

#encode(value) ⇒ Object



660
661
662
# File 'lib/protobuf/message/field.rb', line 660

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