Class: Protobuf::Field::BoolField
- Inherits:
-
VarintField
- Object
- BaseField
- VarintField
- Protobuf::Field::BoolField
- Defined in:
- lib/protobuf/field/bool_field.rb
Constant Summary collapse
- ONE =
1
- FALSE_ENCODE =
[0].pack('C')
- FALSE_STRING =
"false".freeze
- FALSE_VALUES =
[false, FALSE_STRING].freeze
- TRUE_ENCODE =
[1].pack('C')
- TRUE_STRING =
"true".freeze
- TRUE_VALUES =
[true, TRUE_STRING].freeze
- ACCEPTABLES =
[true, false, TRUE_STRING, FALSE_STRING].freeze
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
Protobuf::Field::BaseField::OBJECT_MODULE, Protobuf::Field::BaseField::PACKED_TYPES
Instance Attribute Summary
Attributes inherited from BaseField
#default_value, #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!(val) ⇒ Object
- #decode(value) ⇒ Object
- #encode(value) ⇒ Object
Methods inherited from VarintField
Methods inherited from BaseField
#default, #define_encode_to_stream!, #define_field_and_present_predicate!, #define_field_predicate!, #define_set_field!, #define_set_method!, #define_to_message_hash!, #define_value_from_values!, #define_value_from_values_for_serialization!, #deprecated?, #encode_to_stream, #enum?, #extension?, #field?, #field_and_present?, #fully_qualified_name_only!, #initialize, #map?, #message?, #optional?, #packed?, #repeated?, #repeated_message?, #required?, #set, #set_default_value!, #set_field, #set_map!, #set_repeated_message!, #tag_encoded, #to_message_hash, #to_message_hash_with_string_key, #to_s, #value_from_values, #value_from_values_for_serialization, #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
19 20 21 |
# File 'lib/protobuf/field/bool_field.rb', line 19 def self.default false end |
Instance Method Details
#acceptable?(val) ⇒ Boolean
Public Instance Methods
27 28 29 |
# File 'lib/protobuf/field/bool_field.rb', line 27 def acceptable?(val) ACCEPTABLES.include?(val) end |
#coerce!(val) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/protobuf/field/bool_field.rb', line 31 def coerce!(val) if TRUE_VALUES.include?(val) true elsif FALSE_VALUES.include?(val) false else fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end end |
#decode(value) ⇒ Object
41 42 43 |
# File 'lib/protobuf/field/bool_field.rb', line 41 def decode(value) value == ONE end |
#encode(value) ⇒ Object
45 46 47 |
# File 'lib/protobuf/field/bool_field.rb', line 45 def encode(value) value ? TRUE_ENCODE : FALSE_ENCODE end |