CBOR-XS

 view release on metacpan or  search on metacpan

XS.pm  view on Meta::CPAN

=item $value = $tagged->value

=item $new_value = $tagged->value ($new_value)

Access/mutate the tagged value.

=back

=cut

sub tag($$) {
   bless [@_], CBOR::XS::Tagged::;
}

sub CBOR::XS::Tagged::tag {
   $_[0][0] = $_[1] if $#_;
   $_[0][0]
}

sub CBOR::XS::Tagged::value {
   $_[0][1] = $_[1] if $#_;

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

# examples from rfc7049

use Data::Dumper;
use CBOR::XS;

binmode DATA;
binmode STDOUT, ":utf8";

my $test;

sub ok($;$) {
   print $_[0] ? "" : "not ", "ok ", ++$test, " - $_[1]\n";
}

$Data::Dumper::Terse     = 1;
$Data::Dumper::Sortkeys  = 1;
$Data::Dumper::Pair      = ',';
$Data::Dumper::Useqq     = 1;
$Data::Dumper::Indent    = 0;
$Data::Dumper::Quotekeys = 1;

t/57_incr.t  view on Meta::CPAN

BEGIN { $| = 1; print "1..123\n"; }

use CBOR::XS;

print "ok 1\n";
my $tst = 1;

sub tst($$) {
   my ($cbor, $correct) = @_;

   my $dec = CBOR::XS->new;

   # chop
   for my $step (1 .. length $cbor) {
      my $buf = "";
      my @cbor;

      $dec->incr_reset;

t/57_incr.t  view on Meta::CPAN

      }

      print length $buf ? "not " : "", "ok ", ++$tst, "\n";

      my $enc = join " ", map +(unpack "H*", encode_cbor $_), @cbor;

      print $enc eq $correct ? "" : "not ", "ok ", ++$tst, " # ($step) $enc eq $correct\n";
   }
}

sub err($$) {
   if (eval { CBOR::XS->new->max_size (1e3)->incr_parse ($_[0]); 1 }) {
      print "not ok ", ++$tst, " # unexpected success\n";
   } elsif ($@ =~ $_[1]) {
      print "ok ", ++$tst, "\n";
   } else {
      print "not ok ", ++$tst, " # $@\n";
   }
}

tst "\x81\x82\x81\x80\x80\x80", "8182818080 80";

t/99_binary.t  view on Meta::CPAN

BEGIN { $| = 1; print "1..6144\n"; }

use CBOR::XS;

our $test;
sub ok($;$) {
   print $_[0] ? "" : "not ", "ok ", ++$test, " - $_[1]\n";
}

sub test($) {
   my $js;

   $js = CBOR::XS->new->shrink->encode ([$_[0]]);
   ok ($_[0] eq ((decode_cbor $js)->[0]), 0);
   $js = CBOR::XS->new->encode ([$_[0]]);
   ok ($_[0] eq (CBOR::XS->new->shrink->decode($js))->[0], 1);
}

srand 0; # doesn't help too much, but its at least more deterministic



( run in 2.253 seconds using v1.01-cache-2.11-cpan-65fba6d93b7 )