Module: CBOR::HashHelper

Defined in:
lib/libcbor/helpers.rb

Overview

Provides the #to_cbor (or equivalent) method for Hashes

Instance Method Summary collapse

Instance Method Details

#__libcbor_to_cborString

Encodes Hashes. The resulting item is always a definite map.

The members are encoded recursively using the to_cbor method or its equivalent

Returns:

  • (String)

    The CBOR representation



91
92
93
94
95
96
97
98
99
# File 'lib/libcbor/helpers.rb', line 91

def __libcbor_to_cbor
	@@bfr ||= FFI::Buffer.new(:uchar, 9)
	header = @@bfr.get_bytes(0, LibCBOR.cbor_encode_map_start(count, @@bfr, 9))
	each do |member|
		header += member.first.public_send(CBOR.method_name)
		header += member.last.public_send(CBOR.method_name)
	end
	header
end