Class: IcAgent::Candid::RecClass

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

Constant Summary collapse

@@counter =
0

Instance Method Summary collapse

Methods inherited from ConstructType

#check_type

Methods inherited from BaseType

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

Constructor Details

#initializeRecClass

Returns a new instance of RecClass.



1002
1003
1004
1005
1006
1007
# File 'lib/ic_agent/candid.rb', line 1002

def initialize
  super()
  @id = @@counter
  @@counter += 1
  @type = nil
end

Instance Method Details

#_build_type_table_impl(type_table) ⇒ Object



1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
# File 'lib/ic_agent/candid.rb', line 1043

def _build_type_table_impl(type_table)
  if @type.nil?
    raise 'Recursive type uninitialized'
  else
    if !get_type.is_a?(PrimitiveType)
      type_table.add(self, '')
      @type.build_type_table(type_table)
      type_table.merge(self, @type.name)
    end
  end
end

#covariant(x) ⇒ Object



1021
1022
1023
1024
1025
# File 'lib/ic_agent/candid.rb', line 1021

def covariant(x)
  return false if @type.nil?

  @type.covariant(x)
end

#decode_value(b, t) ⇒ Object



1055
1056
1057
1058
1059
1060
1061
# File 'lib/ic_agent/candid.rb', line 1055

def decode_value(b, t)
  if @type.nil?
    raise 'Recursive type uninitialized'
  else
    @type.decode_value(b, t)
  end
end

#displayObject



1067
1068
1069
1070
1071
1072
1073
# File 'lib/ic_agent/candid.rb', line 1067

def display
  if @type.nil?
    raise 'Recursive type uninitialized'
  else
    "#{name}.#{@type.name}"
  end
end

#encode_type(type_table) ⇒ Object



1035
1036
1037
1038
1039
1040
1041
# File 'lib/ic_agent/candid.rb', line 1035

def encode_type(type_table)
  if @type.is_a?(PrimitiveType)
    @type.encode_type(type_table)
  else
    super.encode_type(type_table)
  end
end

#encode_value(val) ⇒ Object



1027
1028
1029
1030
1031
1032
1033
# File 'lib/ic_agent/candid.rb', line 1027

def encode_value(val)
  if @type.nil?
    raise 'Recursive type uninitialized'
  else
    @type.encode_value(val)
  end
end

#fill(t) ⇒ Object



1009
1010
1011
# File 'lib/ic_agent/candid.rb', line 1009

def fill(t)
  @type = t
end

#get_typeObject



1013
1014
1015
1016
1017
1018
1019
# File 'lib/ic_agent/candid.rb', line 1013

def get_type
  if @type.is_a?(RecClass)
    @type.get_type
  else
    @type
  end
end

#nameObject



1063
1064
1065
# File 'lib/ic_agent/candid.rb', line 1063

def name
  "rec_#{@id}"
end