Module: CBOR::ByteStringHelper

Defined in:
lib/libcbor/helpers.rb

Instance Method Summary collapse

Instance Method Details

#__libcbor_to_cborString

Encodes CBOR::ByteStrings. The result is always a definite string.

Returns:

  • (String)

    The CBOR representation



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/libcbor/helpers.rb', line 54

def __libcbor_to_cbor
	@@item ||= LibCBOR.cbor_new_definite_bytestring
	string = FFI::MemoryPointer.from_string(self)
	out_bfr = FFI::MemoryPointer.new :pointer
	out_bfr_len = FFI::MemoryPointer.new :size_t
	LibCBOR.cbor_bytestring_set_handle(@@item, string, bytes.length)
	res_len = LibCBOR.cbor_serialize_alloc(@@item, out_bfr, out_bfr_len)
	out_bfr.read_pointer.get_bytes(0, res_len).tap do
		LibC.free(out_bfr.read_pointer)
	end
end