Class: IcAgent::Candid::BoolClass

Inherits:
PrimitiveType show all
Defined in:
lib/ic_agent/candid.rb

Instance Method Summary collapse

Methods inherited from PrimitiveType

#_build_type_table_impl, #check_type

Methods inherited from BaseType

_build_type_table_impl, #build_type_table, check_type, covariant, decode_value, #display, encode_type, encode_value

Constructor Details

#initializeBoolClass

Returns a new instance of BoolClass.



239
240
241
# File 'lib/ic_agent/candid.rb', line 239

def initialize
  super
end

Instance Method Details

#covariant(x) ⇒ Object



243
244
245
# File 'lib/ic_agent/candid.rb', line 243

def covariant(x)
  x.is_a?(TrueClass) || x.is_a?(FalseClass)
end

#decode_value(b, t) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/ic_agent/candid.rb', line 255

def decode_value(b, t)
  check_type(t)
  byte = IcAgent::Candid.safe_read_byte(b)
  str_io = StringIO.new
  str_io.putc(byte.hex)
  if LEB128.decode_signed(str_io) == 1
    true
  elsif LEB128.decode_signed(str_io) == 0
    false
  else
    raise ValueError, 'Boolean value out of range'
  end
end

#encode_type(type_table = nil) ⇒ Object



251
252
253
# File 'lib/ic_agent/candid.rb', line 251

def encode_type(type_table = nil)
  LEB128.encode_signed(TypeIds::Bool).string
end

#encode_value(val) ⇒ Object



247
248
249
# File 'lib/ic_agent/candid.rb', line 247

def encode_value(val)
  LEB128.encode_signed(val ? 1 : 0).string
end

#idObject



273
274
275
# File 'lib/ic_agent/candid.rb', line 273

def id
  TypeIds::Bool
end

#nameObject



269
270
271
# File 'lib/ic_agent/candid.rb', line 269

def name
  'bool'
end