Class: Protopuffs::Bool

Inherits:
MessageField show all
Defined in:
lib/protopuffs/message/field.rb

Instance Attribute Summary

Attributes inherited from MessageField

#default, #identifier, #tag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MessageField

factory, #key, #optional?, #repeated?, shift_tag, #to_wire_format_with_value

Constructor Details

#initialize(modifier, identifier, tag, default = nil) ⇒ Bool

Returns a new instance of Bool.



70
71
72
# File 'lib/protopuffs/message/field.rb', line 70

def initialize(modifier, identifier, tag, default = nil)
  super(modifier, identifier, tag, default || false)
end

Class Method Details

.encode(value) ⇒ Object



81
# File 'lib/protopuffs/message/field.rb', line 81

def self.encode(value); VarInt.encode(value ? 1 : 0) end

.shift(buffer) ⇒ Object



74
# File 'lib/protopuffs/message/field.rb', line 74

def self.shift(buffer); VarInt.shift(buffer) end

.wire_typeObject



73
# File 'lib/protopuffs/message/field.rb', line 73

def self.wire_type;     WireType::VARINT end

Instance Method Details

#decode(value_bytes) ⇒ Object



75
76
77
78
79
80
# File 'lib/protopuffs/message/field.rb', line 75

def decode(value_bytes)
  value = VarInt.decode(value_bytes)
  value = true  if value == 1
  value = false if value == 0
  value
end