Class: Protobuf::Field::BoolField

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VarintField

decode, encode, #wire_type

Methods inherited from BaseField

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

Class Method Details

.defaultObject



580
581
582
# File 'lib/protobuf/message/field.rb', line 580

def self.default
  false
end

Instance Method Details

#acceptable?(val) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (TypeError)


584
585
586
587
# File 'lib/protobuf/message/field.rb', line 584

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

#decode(value) ⇒ Object



589
590
591
# File 'lib/protobuf/message/field.rb', line 589

def decode(value)
  value == 1
end

#encode(value) ⇒ Object



593
594
595
# File 'lib/protobuf/message/field.rb', line 593

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