Module: CBOR::Packed::Tagged_Packed_CBOR

Defined in:
lib/cbor-packed.rb

Instance Method Summary collapse

Instance Method Details

#cbor_visit(&b) ⇒ Object



255
256
257
258
259
# File 'lib/cbor-packed.rb', line 255

def cbor_visit(&b)
  if yield self
    value.cbor_visit(&b)
  end
end

#to_packed_cbor1(packer = Packer.from_item(self)) ⇒ Object



295
296
297
298
299
300
301
# File 'lib/cbor-packed.rb', line 295

def to_packed_cbor1(packer = Packer.from_item(self))
  if c = packer.has(self)
    c
  else
    CBOR::Tagged.new(tag, value.to_packed_cbor1(packer))
  end
end

#to_unpacked_cborObject



260
261
262
263
264
265
266
267
268
269
270
# File 'lib/cbor-packed.rb', line 260

def to_unpacked_cbor
  if tag == PACKED_TAG
    # check that this really is an array
    # warn value.to_yaml
    ma, pa, sa, pv = value
    unpacker = Unpacker.new(ma, pa, sa)
    pv.to_unpacked_cbor1(unpacker)
  else
    fail "error message here"
  end
end

#to_unpacked_cbor1(unpacker) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/cbor-packed.rb', line 271

def to_unpacked_cbor1(unpacker)
  case tag
  when REF_TAG
    if Integer === value
      unpacker(untag(value))
    else
      unpacker.unprefix(0).packed_merge value, unpacker
    end
  when 225...256
    unpacker.unprefix(tag-(256-32)).packed_merge value, unpacker
  when 28704...32768      # (- 28704 (- 32768 4096)) == 32
    unpacker.unprefix(tag-(32768-4096)).packed_merge value, unpacker
  when 1879052288...2147483648 # (- 1879052288 (- 2147483648 268435456)) == 4096
    unpacker.unprefix(tag-(2147483648-268435456)).packed_merge value, unpacker
  when 216...224
    value.packed_merge unpacker.unsuffix(tag-216), unpacker
  when 27647...28672
    value.packed_merge unpacker.unsuffix(tag-(28672-1024)), unpacker
  when 1811940352...1879048192
    value.packed_merge unpacker.unsuffix(tag-(1879048192-67108864)), unpacker
  else
    CBOR::Tagged.new(tag, value.to_unpacked_cbor1(unpacker))
  end
end