Class: CBOR::Xbox
Constant Summary
Constants inherited from Box
Instance Attribute Summary
Attributes inherited from Box
Instance Method Summary collapse
Methods inherited from Box
#cbor_diagnostic, from_instance, #inspect, make_head, #to_s
Instance Method Details
#to_cbor ⇒ Object
67 68 69 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 |
# File 'lib/cbor-diag-support.rb', line 67 def to_cbor enc = CBOR.encode(value) if ei = [: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] # when 31; XXX conflicting EI information 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 |