Class: Protobuf::Field::BoolField

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

Protobuf::Field::BaseField::PACKED_TYPES

Instance Attribute Summary

Attributes inherited from BaseField

#default, #default_value, #deprecated, #extension, #getter_method_name, #message_class, #name, #optional, #packed, #repeated, #required, #rule, #setter_method_name, #tag, #type_class

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VarintField

encode, #wire_type

Methods inherited from BaseField

#deprecated?, #enum?, #extension?, #initialize, #message?, #optional?, #packed?, #repeated?, #repeated_message?, #required?, #set, #to_s, #type, #warn_if_deprecated

Constructor Details

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

Class Method Details

.defaultObject

Class Methods



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

def self.default
  false
end

Instance Method Details

#acceptable?(val) ⇒ Boolean

Public Instance Methods

Returns:

  • (Boolean)


20
21
22
# File 'lib/protobuf/field/bool_field.rb', line 20

def acceptable?(val)
  [true, false].include?(val)
end

#decode(value) ⇒ Object



24
25
26
# File 'lib/protobuf/field/bool_field.rb', line 24

def decode(value)
  value == 1
end

#encode(value) ⇒ Object



28
29
30
# File 'lib/protobuf/field/bool_field.rb', line 28

def encode(value)
  [value ? 1 : 0].pack('C')
end