Module: CBOR::Packed::Hash_Packed_CBOR

Defined in:
lib/cbor-packed.rb

Instance Method Summary collapse

Instance Method Details

#cbor_visit(&b) ⇒ Object



452
453
454
455
456
457
458
459
# File 'lib/cbor-packed.rb', line 452

def cbor_visit(&b)
  if yield self
    each do |k, v|
      k.cbor_visit(&b)
      v.cbor_visit(&b)
    end
  end
end

#packed_merge(other, unpacker) ⇒ Object



471
472
473
474
475
476
477
478
479
# File 'lib/cbor-packed.rb', line 471

def packed_merge(other, unpacker)
  rhs = other
  until Hash === rhs
    rhso = rhs
    rhs = rhs.to_unpacked_cbor1(unpacker)
    fail ArgumentError, "*** In #{self.inspect}, cannot further unpack #{rhs.inspect}" unless rhso != rhs
  end
  to_unpacked_cbor1(unpacker).merge rhs
end

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



463
464
465
466
467
468
469
470
# File 'lib/cbor-packed.rb', line 463

def to_packed_cbor1(packer = Packer.from_item(self))
  if c = packer.has(self)
    c.to_packed_cbor1(packer)
  else
    # TODO: Find useful prefixes
    Hash[map {|k, v| [k.to_packed_cbor1(packer), v.to_packed_cbor1(packer)]}]
  end
end

#to_unpacked_cbor1(unpacker) ⇒ Object



460
461
462
# File 'lib/cbor-packed.rb', line 460

def to_unpacked_cbor1(unpacker)
  Hash[map {|k, v| [k.to_unpacked_cbor1(unpacker), v.to_unpacked_cbor1(unpacker)]}]
end