--- CBOR-XS/XS.pm 2013/12/10 15:31:40 1.39 +++ CBOR-XS/XS.pm 2016/04/24 09:11:14 1.50 @@ -66,7 +66,7 @@ use common::sense; -our $VERSION = 1.12; +our $VERSION = 1.41; our @ISA = qw(Exporter); our @EXPORT = qw(encode_cbor decode_cbor); @@ -220,8 +220,13 @@ If C<$enable> is false (the default), then C will throw an error when it encounters a self-referential/cyclic data structure. +FUTURE DIRECTION: the motivation behind this option is to avoid I +cycles - future versions of this module might chose to decode cyclic data +structures using weak references when this option is off, instead of +throwing an error. + This option does not affect C in any way - shared values and -references will always be decoded properly if present. +references will always be encoded properly if present. =item $cbor = $cbor->pack_strings ([$enable]) @@ -478,7 +483,7 @@ 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 hahs is encoded. +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. @@ -811,7 +816,7 @@ objects using the C methods (the L object serialisation protocol). See L for details. -=item 28, 29 (shareable, sharedref, L ) +=item 28, 29 (shareable, sharedref, L) These tags are automatically decoded when encountered (and they do not result in a cyclic data structure, see C), resulting in @@ -831,7 +836,7 @@ to be supported in the encoder. The decoder, however, will decode these values as shared values. -=item 256, 25 (stringref-namespace, stringref, L ) +=item 256, 25 (stringref-namespace, stringref, L) These tags are automatically decoded when encountered. They are only encoded, however, when C is enabled. @@ -905,48 +910,6 @@ =cut -our %FILTER = ( - # 0 # rfc4287 datetime, utf-8 - # 1 # unix timestamp, any - - 2 => sub { # pos bigint - require Math::BigInt; - Math::BigInt->new ("0x" . unpack "H*", pop) - }, - - 3 => sub { # neg bigint - require Math::BigInt; - -Math::BigInt->new ("0x" . unpack "H*", pop) - }, - - 4 => sub { # decimal fraction, array - require Math::BigFloat; - Math::BigFloat->new ($_[1][1] . "E" . $_[1][0]) - }, - - 5 => sub { # bigfloat, array - require Math::BigFloat; - scalar Math::BigFloat->new ($_[1][1])->blsft ($_[1][0], 2) - }, - - 21 => sub { pop }, # expected conversion to base64url encoding - 22 => sub { pop }, # expected conversion to base64 encoding - 23 => sub { pop }, # expected conversion to base16 encoding - - # 24 # embedded cbor, byte string - - 32 => sub { - require URI; - URI->new (pop) - }, - - # 33 # base64url rfc4648, utf-8 - # 34 # base64 rfc46484, utf-8 - # 35 # regex pcre/ecma262, utf-8 - # 36 # mime message rfc2045, utf-8 -); - - =head1 CBOR and JSON CBOR is supposed to implement a superset of the JSON data model, and is, @@ -1019,7 +982,8 @@ =head1 LIMITATIONS ON PERLS WITHOUT 64-BIT INTEGER SUPPORT On perls that were built without 64 bit integer support (these are rare -nowadays, even on 32 bit architectures), support for any kind of 64 bit +nowadays, even on 32 bit architectures, as all major Perl distributions +are built with 64 bit integer support), support for any kind of 64 bit integer in CBOR is very limited - most likely, these 64 bit values will be truncated, corrupted, or otherwise not decoded correctly. This also includes string, array and map sizes that are stored as 64 bit integers. @@ -1054,7 +1018,7 @@ # else either. Whats incredibe over standard strptime totally escapes me. # doesn't do fractional times, either. sigh. # In fact, it's all a lie, it uses whatever strptime it wants, and of course, - # they are all incomptible. The openbsd one simply ignores %z (but according to the + # they are all incompatible. The openbsd one simply ignores %z (but according to the # docs, it would be much more incredibly flexible indeed. If it worked, that is.). scalar eval { my $s = $_[1]; @@ -1092,7 +1056,7 @@ 5 => sub { # bigfloat, array require Math::BigFloat; - scalar Math::BigFloat->new ($_[1][1])->blsft ($_[1][0], 2) + scalar Math::BigFloat->new ($_[1][1]) * Math::BigFloat->new (2)->bpow ($_[1][0]) }, 21 => sub { pop }, # expected conversion to base64url encoding @@ -1138,7 +1102,7 @@ } sub Time::Piece::TO_CBOR { - tag 1, $_[0]->epoch + tag 1, 0 + $_[0]->epoch } XSLoader::load "CBOR::XS", $VERSION;