CBOR-XS

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Perl extension CBOR::XS

TODO: pack_keys?
TODO: document encode_cbor_sharing?
TODO: large negative integers
TODO: type cast tests.
TODO: round-tripping of types, such as float16 - maybe types::Serialiser support?
TODO: possibly implement https://peteroupc.github.io/CBOR/extended.html, but NaNs are nonportable. rely on libecb?
TODO: https://github.com/svaarala/cbor-specs/blob/master/cbor-nonutf8-string-tags.rst, but maybe that is overkill?

1.87 Fri 08 Sep 2023 22:14:18 CEST
        - shared references were not decoded correctly: instead of getting
          multiple references to the same object, you got the same
          reference to the same object, causing a number of issues. For
          example, modifying the reference would modify all places the
          reference was used, and encoding the decoded structure would
          unshare the previously shared hashes, as trheir reference count
          would be 1. Fixing this was rather involved, as perl lacks the

README  view on Meta::CPAN

    2, 3 (positive/negative bignum)
        These tags are decoded into Math::BigInt objects. The corresponding
        "Math::BigInt::TO_CBOR" method encodes "small" bigints into normal
        CBOR integers, and others into positive/negative CBOR bignums.

    4, 5, 264, 265 (decimal fraction/bigfloat)
        Both decimal fractions and bigfloats are decoded into Math::BigFloat
        objects. The corresponding "Math::BigFloat::TO_CBOR" method *always*
        encodes into a decimal fraction (either tag 4 or 264).

        NaN and infinities are not encoded properly, as they cannot be
        represented in CBOR.

        See "BIGNUM SECURITY CONSIDERATIONS" for more info.

    30 (rational numbers)
        These tags are decoded into Math::BigRat objects. The corresponding
        "Math::BigRat::TO_CBOR" method encodes rational numbers with
        denominator 1 via their numerator only, i.e., they become normal
        integers or "bignums".

XS.pm  view on Meta::CPAN

These tags are decoded into L<Math::BigInt> objects. The corresponding
C<Math::BigInt::TO_CBOR> method encodes "small" bigints into normal CBOR
integers, and others into positive/negative CBOR bignums.

=item 4, 5, 264, 265 (decimal fraction/bigfloat)

Both decimal fractions and bigfloats are decoded into L<Math::BigFloat>
objects. The corresponding C<Math::BigFloat::TO_CBOR> method I<always>
encodes into a decimal fraction (either tag 4 or 264).

NaN and infinities are not encoded properly, as they cannot be represented
in CBOR.

See L<BIGNUM SECURITY CONSIDERATIONS> for more info.

=item 30 (rational numbers)

These tags are decoded into L<Math::BigRat> objects. The corresponding
C<Math::BigRat::TO_CBOR> method encodes rational numbers with denominator
C<1> via their numerator only, i.e., they become normal integers or
C<bignums>.

ecb.h  view on Meta::CPAN


ecb_function_ ecb_const uint32_t ecb_binary16_to_binary32 (uint32_t x);
ecb_function_ ecb_const uint32_t
ecb_binary16_to_binary32 (uint32_t x)
{
  unsigned int s = (x & 0x8000) << (31 - 15);
  int          e = (x >> 10) & 0x001f;
  unsigned int m =  x        & 0x03ff;

  if (ecb_expect_false (e == 31))
    /* infinity or NaN */
    e = 255 - (127 - 15);
  else if (ecb_expect_false (!e))
    {
      if (ecb_expect_true (!m))
        /* zero, handled by code below by forcing e to 0 */
        e = 0 - (127 - 15);
      else
        {
          /* subnormal, renormalise */
          unsigned int s = 10 - ecb_ld32 (m);

ecb.h  view on Meta::CPAN

        unsigned int half = (1 << (bits - 1)) - 1;
        unsigned int even = (m >> bits) & 1;

        /* if this overflows, we will end up with a normalised number */
        m = (m + half + even) >> bits;
      }

      return s | m;
    }

  /* handle NaNs, preserve leftmost nan bits, but make sure we don't turn them into infinities */
  m >>= 13;

  return s | 0x7c00 | m | !m;
}

/*******************************************************************************/
/* fast integer to ascii */

/*
 * This code is pretty complicated because it is general. The idea behind it,

t/50_rfc.t  view on Meta::CPAN

<  1.5                           0xf93e00
<  65504                         0xf97bff
<  100000                        0xfa47c35000
*  3.4028234663852886e+38        0xfa7f7fffff
*  1e+300                        0xfb7e37e43c8800759c
   5.960464477539063e-8          0xf90001
   0.00006103515625              0xf90400
<  -4                            0xf9c400
*  -4.1                          0xfbc010666666666666
   Infinity                      0xf97c00
   NaN                           0xf97e00
   -Infinity                     0xf9fc00
*  Infinity                      0xfa7f800000
   NaN                           0xfa7fc00000
*  -Infinity                     0xfaff800000
   Infinity                      0xfb7ff0000000000000
*  NaN                           0xfb7ff8000000000000
   -Infinity                     0xfbfff0000000000000
*  false                         0xf4
*  true                          0xf5
*  null                          0xf6
*  undefined                     0xf7
   simple(16)                    0xf0
   simple(24)                    0xf818
   simple(255)                   0xf8ff
   0("2013-03-21T20:04:00Z")     0xc074323031332d30332d32315432303a30343a30305a
*  1(1363896240)                 0xc11a514b67b0



( run in 0.275 second using v1.01-cache-2.11-cpan-4d50c553e7e )