class IcAgent::Candid::TypeTable
Attributes
idx[RW]
typs[RW]
Public Class Methods
new()
click to toggle source
# File lib/ic_agent/candid.rb, line 50 def initialize @typs = [] @idx = {} end
Public Instance Methods
add(obj, buf)
click to toggle source
# File lib/ic_agent/candid.rb, line 59 def add(obj, buf) idx = @typs.length @idx[obj.name] = idx @typs.append(buf) end
encode()
click to toggle source
# File lib/ic_agent/candid.rb, line 78 def encode l = 0 @typs.each do |t| if t.length != 0 l += 1 end end length = LEB128.encode_signed(l).string buf = @typs.join('') return "#{length}#{buf}" end
has(obj)
click to toggle source
# File lib/ic_agent/candid.rb, line 55 def has(obj) return @idx.has_key?(obj.name) end
index_of(type_name)
click to toggle source
# File lib/ic_agent/candid.rb, line 91 def index_of(type_name) raise ValueError, "Missing type index for #{type_name}" if !@idx.has_key?(type_name) return LEB128.encode_signed(@idx[type_name] | 0).string end
merge(obj, knot)
click to toggle source
# File lib/ic_agent/candid.rb, line 65 def merge(obj, knot) idx = self.has(obj) ? @idx[obj.name] : nil knot_idx = @idx.has_key?(knot) ? @idx[knot] : nil raise ValueError, "Missing type index for #{obj.name}" if idx == nil raise ValueError, "Missing type index for #{knot}" if knot_idx == nil @typs[idx] = @typs[knot_idx] # delete the type @typs.delete_at(knot_idx) @idx.delete(knot) end