CBOR-Free

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

- Lighten memory usage significantly by deferring load of Types::Serialiser
  until it’s needed.
- Tweak documentation a bit for accuracy.

0.10 14 Jun 2019
- Fix test & number stringification on 32-bit Perls (broken in 0.09).

0.09 14 Jun 2019
- Further optimizations.
- Test fixes (obscure MSWin32?)
- Always encode Inf, -Inf, and NaN to half-precision.
- Fix off-by-one in error message when trying to decode -(~0).

0.08 10 May 2019
- Further decoding speed-ups.

0.07 9 May 2019
- Dramatic speed-up in both encode and decode.
- Decode now accepts only integers or strings as map keys.

0.06 3 May 2019

easyxs/ppport.h  view on Meta::CPAN

    s++; if (s == send || (*s != 'F' && *s != 'f')) return 0;
    s++; if (s < send && (*s == 'I' || *s == 'i')) {
      s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
      s++; if (s == send || (*s != 'I' && *s != 'i')) return 0;
      s++; if (s == send || (*s != 'T' && *s != 't')) return 0;
      s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
      s++;
    }
    sawinf = 1;
  } else if (*s == 'N' || *s == 'n') {
    /* XXX TODO: There are signaling NaNs and quiet NaNs. */
    s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
    s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
    s++;
    sawnan = 1;
  } else
    return 0;

  if (sawinf) {
    numtype &= IS_NUMBER_NEG; /* Keep track of sign  */
    numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT;

t/examples.t  view on Meta::CPAN

    is_deeply(
        $got,
        $t->[0],
        sprintf("Round-trip: $t->[1]"),
    ) or Devel::Peek::Dump($got);
}

# NB: Different perls have historically represented these values
# using different strings:
#   - Modern perls all appear to use: inf nan -inf
#   - Some older perls used Inf NaN -Inf
#   - Others (e.g., Strawberry 5.12.2) used 1.#INF 1.#QNAN -1.#INF
#   - Still others (Solaris) used Infinity NaN -Infinity
my $inf = unpack("f>", "\x7f\x80\x00\x00");
my $nan = unpack("f>", "\x7f\xc0\x00\x00");
my $neginf = unpack("f>", "\xff\x80\x00\x00");

sub _pre_522_lc {
    return( $^V ge v5.22.0 ? $_[0] : lc $_[0] );
}

my @decode = (
    [ -1 => '20' ],

t/float.t  view on Meta::CPAN

    is(
        sprintf('%v.02x', CBOR::Free::encode($neginf)),
        'f9.fc.00',
        '-Inf encodes to half-precision as expected',
    );
}

is(
    sprintf('%v.02x', CBOR::Free::encode($nan)),
    'f9.7e.00',
    'NaN encodes to half-precision as expected',
);

sub _cmpbin {
    my ($got, $expect, $label) = @_;

    $_ = sprintf('%v.02x', $_) for ($got, $expect);

    return is( $got, $expect, $label );
}

t_manual/upstream_test_vectors.t  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;
use Test::FailWarnings;

my %diagnostic = (
    Infinity => unpack("f>", "\x7f\x80\x00\x00"),
    NaN => unpack("f>", "\x7f\xc0\x00\x00"),
    '-Infinity' => unpack("f>", "\xff\x80\x00\x00"),
    undefined => undef,
);

diag explain \%ENV;

SKIP: {
    skip "Only for interactive testing!" if $ENV{'NONINTERACTIVE_TESTING'};

    my $tests_ar = eval {



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