Class: IcAgent::Candid::TextClass

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

#initializeTextClass

Returns a new instance of TextClass.



312
313
314
# File 'lib/ic_agent/candid.rb', line 312

def initialize
  super
end

Instance Method Details

#covariant(x) ⇒ Object



316
317
318
# File 'lib/ic_agent/candid.rb', line 316

def covariant(x)
  x.is_a?(String)
end

#decode_value(b, t) ⇒ Object



330
331
332
333
334
335
# File 'lib/ic_agent/candid.rb', line 330

def decode_value(b, t)
  check_type(t)
  length = IcAgent::Candid.leb128u_decode(b).to_i
  buf = IcAgent::Candid.safe_read(b, length)
  buf.hex2str
end

#encode_type(type_table = nil) ⇒ Object



326
327
328
# File 'lib/ic_agent/candid.rb', line 326

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

#encode_value(val) ⇒ Object



320
321
322
323
324
# File 'lib/ic_agent/candid.rb', line 320

def encode_value(val)
  buf = val.encode(Encoding::UTF_8)
  length = LEB128.encode_signed(buf.length).string
  length + buf
end

#idObject



341
342
343
# File 'lib/ic_agent/candid.rb', line 341

def id
  TypeIds::Text
end

#nameObject



337
338
339
# File 'lib/ic_agent/candid.rb', line 337

def name
  'text'
end