Class: CBOR::Ibox
- Inherits:
-
Box
- Object
- Struct
- Box
- CBOR::Ibox
show all
- Defined in:
- lib/cbor-diag-support.rb
Constant Summary
collapse
- INTEGER_EI =
{
"i" => [23, 0],
"0" => [0xFF, 1],
"1" => [0xFFFF, 2],
"2" => [0xFFFFFFFF, 4],
"3" => [0xFFFFFFFFFFFFFFFF, 8]
}
Instance Attribute Summary
Attributes inherited from Box
#options, #value
Instance Method Summary
collapse
Methods inherited from Box
#cbor_diagnostic, from_number, #inspect, #to_s
Instance Method Details
#make_head(ib, plusbytes, d) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/cbor-diag-support.rb', line 41
def make_head(ib, plusbytes, d)
case plusbytes
when 0
[ib + d].pack("C")
when 1
[ib + 24, d].pack("CC")
when 2
[ib + 25, d].pack("Cn")
when 4
[ib + 26, d].pack("CN")
when 8
[ib + 27, d].pack("CQ>")
else
raise ArgumentError, "cbor-diagnostic: #{plusbytes} plusbytes when encoding head\n"
end
end
|
#to_cbor ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/cbor-diag-support.rb', line 58
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
make_head(ib, plusbytes, d)
else
CBOR.encode(value)
end
end
|