CBOR-XS
view release on metacpan or search on metacpan
refers to the abstract Perl language itself.
=head2 CBOR -> PERL
=over 4
=item integers
CBOR integers become (numeric) perl scalars. On perls without 64 bit
support, 64 bit integers will be truncated or otherwise corrupted.
=item byte strings
Byte strings will become octet strings in Perl (the Byte values 0..255
will simply become characters of the same value in Perl).
=item UTF-8 strings
UTF-8 strings in CBOR will be decoded, i.e. the UTF-8 octets will be
decoded into proper Unicode code points. At the moment, the validity of
the UTF-8 octets will not be validated - corrupt input will result in
corrupted Perl strings.
=item arrays, maps
CBOR arrays and CBOR maps will be converted into references to a Perl
array or hash, respectively. The keys of the map will be stringified
during this process.
=item null
CBOR null becomes C<undef> in Perl.
=item true, false, undefined
These CBOR values become C<Types:Serialiser::true>,
C<Types:Serialiser::false> and C<Types::Serialiser::error>,
respectively. They are overloaded to act almost exactly like the numbers
C<1> and C<0> (for true and false) or to throw an exception on access (for
error). See the L<Types::Serialiser> manpage for details.
=item tagged values
Tagged items consists of a numeric tag and another CBOR value.
See L<TAG HANDLING AND EXTENSIONS> and the description of C<< ->filter >>
for details on which tags are handled how.
=item anything else
Anything else (e.g. unsupported simple values) will raise a decoding
error.
=back
=head2 PERL -> CBOR
The mapping from Perl to CBOR is slightly more difficult, as Perl is a
typeless language. That means this module can only guess which CBOR type
is meant by a perl value.
=over 4
=item hash references
Perl hash references become CBOR maps. As there is no inherent ordering in
hash keys (or CBOR maps), they will usually be encoded in a pseudo-random
order. This order can be different each time a hash is encoded.
Currently, tied hashes will use the indefinite-length format, while normal
hashes will use the fixed-length format.
=item array references
Perl array references become fixed-length CBOR arrays.
=item other references
Other unblessed references will be represented using
the indirection tag extension (tag value C<22098>,
L<http://cbor.schmorp.de/indirection>). CBOR decoders are guaranteed
to be able to decode these values somehow, by either "doing the right
thing", decoding into a generic tagged object, simply ignoring the tag, or
something else.
=item CBOR::XS::Tagged objects
Objects of this type must be arrays consisting of a single C<[tag, value]>
pair. The (numerical) tag will be encoded as a CBOR tag, the value will
be encoded as appropriate for the value. You must use C<CBOR::XS::tag> to
create such objects.
=item Types::Serialiser::true, Types::Serialiser::false, Types::Serialiser::error
These special values become CBOR true, CBOR false and CBOR undefined
values, respectively.
=item other blessed objects
Other blessed objects are serialised via C<TO_CBOR> or C<FREEZE>. See
L<TAG HANDLING AND EXTENSIONS> for specific classes handled by this
module, and L<OBJECT SERIALISATION> for generic object serialisation.
=item simple scalars
Simple Perl scalars (any scalar that is not a reference) are the most
difficult objects to encode: CBOR::XS will encode undefined scalars as
CBOR null values, scalars that have last been used in a string context
before encoding as CBOR strings, and anything else as number value:
# dump as number
encode_cbor [2] # yields [2]
encode_cbor [-3.0e17] # yields [-3e+17]
my $value = 5; encode_cbor [$value] # yields [5]
# used as string, so dump as string (either byte or text)
print $value;
encode_cbor [$value] # yields ["5"]
( run in 1.896 second using v1.01-cache-2.11-cpan-5a3173703d6 )