NAME
CBOR::PP::Decode
SYNOPSIS
my $perlvar = CBOR::PP::Decode::decode($binary);
DESCRIPTION
This implements a CBOR encoder in pure Perl.
MAPPING PERL TO CBOR
Scalars that look like unsigned integers are encoded as such. UTF-8 strings and strings that fit 7-bit ASCII (including floats and negatives) are encoded as text. Any other scalar is encoded as binary.
Note that there is no “right way” to determine whether an arbitrary Perl (non-reference) scalar should be encoded as a string or as a number. The above seems a reasonable enough approach.
UTF-8 strings are encoded as text; others are encoded as binary. Note that UTF-8 string encoding is a bit slower.
undef, Types::Serialiser::true(), and Types::Serialiser::false() are encoded as null, true, and false, respectively.
There is no support for streamed (i.e., indefinite-length) objects.
There is no Perl value that maps to CBOR’s undefined value.
TODO
Add canonicalization support.
Optimize as may be feasible.
AUTHOR
Gasper Software Consulting (FELIPE)
LICENSE
This code is licensed under the same license as Perl itself.
FUNCTIONS
$obj = tag( $NUMBER, $VALUE )
Returns an object that represents a value and its CBOR tag number. For example, to encode a date/time string, you could do:
my $tagged = tag(0, '2013-03-21T20:04:00Z')
encode()
recognizes objects that this function returns and turns them into tagged CBOR values.
METHODS
$cbor = encode( $VALUE, \%OPTS )
Returns a CBOR string that represents the passed $VALUE.
For now this is only called as a static method but may eventually be an instance method as well, for example, to define options like canonicalization.