Class: IcAgent::Candid::TextClass

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

Overview

Represents an IDL Text

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.



318
319
320
# File 'lib/ic_agent/candid.rb', line 318

def initialize
  super
end

Instance Method Details

#covariant(x) ⇒ Object



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

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

#decode_value(b, t) ⇒ Object



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

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



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

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

#encode_value(val) ⇒ Object



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

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

#idObject



347
348
349
# File 'lib/ic_agent/candid.rb', line 347

def id
  TypeIds::Text
end

#nameObject



343
344
345
# File 'lib/ic_agent/candid.rb', line 343

def name
  'text'
end