Method: IcAgent::Candid.get_type

Defined in:
lib/ic_agent/candid.rb

.get_type(raw_table, table, t) ⇒ Object



1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
# File 'lib/ic_agent/candid.rb', line 1523

def self.get_type(raw_table, table, t)
  if t < -24
    raise ValueError, 'not supported type'
  end

  if t < 0
    case t
    when -1
      return BaseTypes.null
    when -2
      return BaseTypes.bool
    when -3
      return BaseTypes.nat
    when -4
      return BaseTypes.int
    when -5
      return BaseTypes.nat8
    when -6
      return BaseTypes.nat16
    when -7
      return BaseTypes.nat32
    when -8
      return BaseTypes.nat64
    when -9
      return BaseTypes.int8
    when -10
      return BaseTypes.int16
    when -11
      return BaseTypes.int32
    when -12
      return BaseTypes.int64
    when -13
      return BaseTypes.float32
    when -14
      return BaseTypes.float64
    when -15
      return BaseTypes.text
    when -16
      return BaseTypes.reserved
    when -17
      return BaseTypes.empty
    when -24
      return BaseTypes.principal
    else
      raise ValueError, "Illegal op_code: #{t}"
    end
  end

  if t >= raw_table.length
    raise ValueError, 'type index out of range'
  end

  return table[t]
end