Class: Protobuf::Field::EnumField
- Inherits:
-
IntegerField
- Object
- BaseField
- VarintField
- IntegerField
- Protobuf::Field::EnumField
- Defined in:
- lib/protobuf/field/enum_field.rb
Constant Summary
Constants inherited from VarintField
VarintField::CACHE_LIMIT, VarintField::INT32_MAX, VarintField::INT32_MIN, VarintField::INT64_MAX, VarintField::INT64_MIN, VarintField::UINT32_MAX, VarintField::UINT64_MAX
Constants inherited from BaseField
Instance Attribute Summary
Attributes inherited from BaseField
#fully_qualified_name, #message_class, #name, #options, #rule, #tag, #type_class
Class Method Summary collapse
-
.default ⇒ Object
Class Methods.
Instance Method Summary collapse
-
#acceptable?(val) ⇒ Boolean
Public Instance Methods.
- #coerce!(value) ⇒ Object
- #decode(value) ⇒ Object
- #encode(value) ⇒ Object
- #enum? ⇒ Boolean
Methods inherited from VarintField
cached_varint, encode, #wire_type
Methods inherited from BaseField
#default, #default_value, #deprecated?, #extension?, #fully_qualified_name_only!, #initialize, #message?, #optional?, #packed?, #repeated?, #repeated_message?, #required?, #set, #tag_encoded, #to_s, #wire_type
Methods included from Logging
initialize_logger, #log_exception, #log_signature, #logger, #sign_message
Constructor Details
This class inherits a constructor from Protobuf::Field::BaseField
Class Method Details
.default ⇒ Object
Class Methods
11 12 13 |
# File 'lib/protobuf/field/enum_field.rb', line 11 def self.default fail NoMethodError, "#{self}.#{__method__} must be called on an instance" end |
Instance Method Details
#acceptable?(val) ⇒ Boolean
Public Instance Methods
19 20 21 |
# File 'lib/protobuf/field/enum_field.rb', line 19 def acceptable?(val) !type_class.fetch(val).nil? end |
#coerce!(value) ⇒ Object
36 37 38 39 40 |
# File 'lib/protobuf/field/enum_field.rb', line 36 def coerce!(value) enum_value = type_class.fetch(value) fail TypeError, "Invalid Enum value: #{value.inspect} for #{name}" unless enum_value enum_value end |
#decode(value) ⇒ Object
27 28 29 30 |
# File 'lib/protobuf/field/enum_field.rb', line 27 def decode(value) decoded = super(value) decoded if acceptable?(decoded) 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
32 33 34 |
# File 'lib/protobuf/field/enum_field.rb', line 32 def enum? true end |