Class: CBOR::Ibox

Inherits:
Box
  • Object
show all
Defined in:
lib/cbor-diag-support.rb

Constant Summary

Constants inherited from Box

Box::INTEGER_EI

Instance Attribute Summary

Attributes inherited from Box

#options, #value

Instance Method Summary collapse

Methods inherited from Box

#cbor_diagnostic, from_instance, #inspect, make_head, #to_s

Instance Method Details

#to_cborObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/cbor-diag-support.rb', line 100

def to_cbor
  if ei = options[:ei]
    maxval, plusbytes = INTEGER_EI[ei]
    raise ArgumentError, "cbor-diagnostic: unknown encoding indicator _#{ei} for Integer\n" unless maxval
    d = value
    ib = if d < 0
           d = -1-d
           0x20
         else
           0x00
         end
    raise ArgumentError, "cbor-diagnostic: #{value} doesn't fit into encoding indicator _#{ei}':\n" unless d <= maxval

    CBOR::Ibox.make_head(ib, plusbytes, d)

    # s = bignum_to_bytes(d)
    # head(0xc0, TAG_BIGNUM_BASE + (ib >> 5))
    # head(0x40, s.bytesize)
  else
    CBOR.encode(value)
  end
end