Class: CBOR::Xbox
- Inherits:
-
Box
- Object
- Struct
- Box
- CBOR::Xbox
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
#b ⇒ Object
69
|
# File 'lib/cbor-diag-support.rb', line 69
def b; value.b end
|
#encoding ⇒ Object
67
|
# File 'lib/cbor-diag-support.rb', line 67
def encoding; value.encoding end
|
#size ⇒ Object
68
|
# File 'lib/cbor-diag-support.rb', line 68
def size; value.size end
|
#to_cbor ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/cbor-diag-support.rb', line 70
def to_cbor
enc = CBOR.encode(value)
if ei = options[:ei]
maxval, plusbytes = INTEGER_EI[ei]
if maxval
ib = enc.getbyte(0) & 0xE0
ai = enc.getbyte(0) & 0x1F
d, replacement = case ai
when 0...24; [ai, 0]
when 24; [enc[1..1].ord, 1]
when 25; [enc[1..2].unpack1("n"), 2]
when 26; [enc[1..4].unpack1("N"), 4]
when 27; [enc[1..8].unpack1("Q>"), 8]
else raise "unknown additional information #{ai} in ib #{ib}"
end
raise ArgumentError, "cbor-diagnostic: #{value} doesn't fit into encoding indicator _#{ei}':\n" unless d <= maxval
ib = enc.getbyte(0) & 0xE0
new_head = CBOR::Ibox.make_head(ib, plusbytes, d)
enc[0..replacement] = new_head
else
if ei == "" && value == ""
enc = CBOR.encode(value.cbor_stream!([]))
else
warn "*** cbor-diagnostic: ignoring unsupported encoding indicator _#{ei} for #{value.inspect}"
end
end
end
enc
end
|