Module: CBOR::FixnumHelper

Defined in:
lib/libcbor/helpers.rb

Overview

Provides the #to_cbor (or equivalent) method for Fixnums

Instance Method Summary collapse

Instance Method Details

#__libcbor_to_cborString

Encodes Fixnums. Width and signedness are handled automatically.

Returns:

  • (String)

    The CBOR representation



7
8
9
10
11
12
13
14
# File 'lib/libcbor/helpers.rb', line 7

def __libcbor_to_cbor
  @@bfr ||= FFI::Buffer.new(:uchar, 9)
  if self >= 0
    @@bfr.get_bytes(0, LibCBOR.cbor_encode_uint(self, @@bfr, 9))
  else
    @@bfr.get_bytes(0, LibCBOR.cbor_encode_negint(-self - 1, @@bfr, 9))
  end
end