Class: IcAgent::Candid::FuncClass
Instance Attribute Summary collapse
Instance Method Summary
collapse
#check_type, #encode_type
Methods inherited from BaseType
_build_type_table_impl, #build_type_table, check_type, covariant, decode_value, encode_type, encode_value
Constructor Details
#initialize(arg_types, ret_types, annotations) ⇒ FuncClass
Returns a new instance of FuncClass.
1079
1080
1081
1082
1083
1084
|
# File 'lib/ic_agent/candid.rb', line 1079
def initialize(arg_types, ret_types, annotations)
super()
@arg_types = arg_types
@ret_types = ret_types
@annotations = annotations
end
|
Instance Attribute Details
#annotations ⇒ Object
Returns the value of attribute annotations.
1077
1078
1079
|
# File 'lib/ic_agent/candid.rb', line 1077
def annotations
@annotations
end
|
#arg_types ⇒ Object
Returns the value of attribute arg_types.
1077
1078
1079
|
# File 'lib/ic_agent/candid.rb', line 1077
def arg_types
@arg_types
end
|
#ret_types ⇒ Object
Returns the value of attribute ret_types.
1077
1078
1079
|
# File 'lib/ic_agent/candid.rb', line 1077
def ret_types
@ret_types
end
|
Instance Method Details
#_build_type_table_impl(type_table) ⇒ Object
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
|
# File 'lib/ic_agent/candid.rb', line 1111
def _build_type_table_impl(type_table)
@arg_types.each { |arg| arg.build_type_table(type_table) }
@ret_types.each { |ret| ret.build_type_table(type_table) }
op_code = LEB128.encode_signed(TypeIds::Func).string
arg_len = LEB128.encode_signed(@arg_types.length).string
args = ''
@arg_types.each { |arg| args += arg.encode_type(type_table) }
ret_len = LEB128.encode_signed(@ret_types.length).string
rets = ''
@ret_types.each { |ret| rets += ret.encode_type(type_table) }
ann_len = LEB128.encode_signed(@annotations.length).string
anns = ''
@annotations.each { |a| anns += _encode_annotation(a) }
type_table.add(self, op_code + arg_len + args + ret_len + rets + ann_len + anns)
end
|
#_encode_annotation(ann) ⇒ Object
1162
1163
1164
1165
1166
1167
1168
1169
1170
|
# File 'lib/ic_agent/candid.rb', line 1162
def _encode_annotation(ann)
if ann == 'query'
return [1].pack('C')
elsif ann == 'oneway'
return [2].pack('C')
else
raise 'Illeagal function annotation'
end
end
|
#decode_value(b, t) ⇒ Object
#display ⇒ Object
1155
1156
1157
1158
1159
1160
|
# File 'lib/ic_agent/candid.rb', line 1155
def display
args = @arg_types.map { |arg| arg.display }.join(', ')
rets = @ret_types.map { |ret| ret.display }.join(', ')
anns = @annotations.join(' ')
"(#{args}) → (#{rets}) #{anns}"
end
|
#encode_value(vals) ⇒ Object
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
|
# File 'lib/ic_agent/candid.rb', line 1092
def encode_value(vals)
principal = vals[0]
method_name = vals[1]
tag = [1].pack('C')
if principal.is_a?(String)
buf = IcAgent::Principal.from_str(principal).bytes
elsif principal.is_a?(String)
buf = principal
else
raise ArgumentError, 'Principal should be string or bytes.'
end
l = LEB128.encode_signed(buf.length).string
canister = tag + l + buf
method = method_name.encode
method_len = LEB128.encode_signed(method.length).string
tag + canister + method_len + method
end
|
#id ⇒ Object
1151
1152
1153
|
# File 'lib/ic_agent/candid.rb', line 1151
def id
TypeIds::Func
end
|
#name ⇒ Object
1144
1145
1146
1147
1148
1149
|
# File 'lib/ic_agent/candid.rb', line 1144
def name
args = @arg_types.map { |arg| arg.name }.join(', ')
rets = @ret_types.map { |ret| ret.name }.join(', ')
anns = @annotations.join(' ')
"(#{args}) → (#{rets}) #{anns}"
end
|