… | |
… | |
64 | |
64 | |
65 | package CBOR::XS; |
65 | package CBOR::XS; |
66 | |
66 | |
67 | use common::sense; |
67 | use common::sense; |
68 | |
68 | |
69 | our $VERSION = 1.86; |
69 | our $VERSION = 1.87; |
70 | our @ISA = qw(Exporter); |
70 | our @ISA = qw(Exporter); |
71 | |
71 | |
72 | our @EXPORT = qw(encode_cbor decode_cbor); |
72 | our @EXPORT = qw(encode_cbor decode_cbor); |
73 | |
73 | |
74 | use Exporter; |
74 | use Exporter; |
… | |
… | |
216 | communication partner supports the value sharing extensions to CBOR |
216 | communication partner supports the value sharing extensions to CBOR |
217 | (L<http://cbor.schmorp.de/value-sharing>), as without decoder support, the |
217 | (L<http://cbor.schmorp.de/value-sharing>), as without decoder support, the |
218 | resulting data structure might be unusable. |
218 | resulting data structure might be unusable. |
219 | |
219 | |
220 | Detecting shared values incurs a runtime overhead when values are encoded |
220 | Detecting shared values incurs a runtime overhead when values are encoded |
221 | that have a reference counter large than one, and might unnecessarily |
221 | that have a reference counter larger than one, and might unnecessarily |
222 | increase the encoded size, as potentially shared values are encoded as |
222 | increase the encoded size, as potentially shared values are encoded as |
223 | shareable whether or not they are actually shared. |
223 | shareable whether or not they are actually shared. |
224 | |
224 | |
225 | At the moment, only targets of references can be shared (e.g. scalars, |
225 | At the moment, only targets of references can be shared (e.g. scalars, |
226 | arrays or hashes pointed to by a reference). Weirder constructs, such as |
226 | arrays or hashes pointed to by a reference). Weirder constructs, such as |
… | |
… | |
245 | isn't prepared for this will not leak memory. |
245 | isn't prepared for this will not leak memory. |
246 | |
246 | |
247 | If C<$enable> is false (the default), then C<decode> will throw an error |
247 | If C<$enable> is false (the default), then C<decode> will throw an error |
248 | when it encounters a self-referential/cyclic data structure. |
248 | when it encounters a self-referential/cyclic data structure. |
249 | |
249 | |
250 | FUTURE DIRECTION: the motivation behind this option is to avoid I<real> |
250 | This option does not affect C<encode> in any way - shared values and |
251 | cycles - future versions of this module might chose to decode cyclic data |
251 | references will always be encoded properly if present. |
252 | structures using weak references when this option is off, instead of |
252 | |
253 | throwing an error. |
253 | =item $cbor = $cbor->allow_weak_cycles ([$enable]) |
|
|
254 | |
|
|
255 | =item $enabled = $cbor->get_allow_weak_cycles |
|
|
256 | |
|
|
257 | This works like C<allow_cycles> in that it allows the resulting data |
|
|
258 | structures to contain cycles, but unlike C<allow_cycles>, those cyclic |
|
|
259 | rreferences will be weak. That means that code that recurrsively walks |
|
|
260 | the data structure must be prepared with cycles, but at least not special |
|
|
261 | precautions must be implemented to free these data structures. |
|
|
262 | |
|
|
263 | Only those references leading to actual cycles will be weakened - other |
|
|
264 | references, e.g. when the same hash or arrray is referenced multiple times |
|
|
265 | in an arrray, will be normal references. |
254 | |
266 | |
255 | This option does not affect C<encode> in any way - shared values and |
267 | This option does not affect C<encode> in any way - shared values and |
256 | references will always be encoded properly if present. |
268 | references will always be encoded properly if present. |
257 | |
269 | |
258 | =item $cbor = $cbor->forbid_objects ([$enable]) |
270 | =item $cbor = $cbor->forbid_objects ([$enable]) |
… | |
… | |
473 | Perl data structure in memory at one time, it does allow you to parse a |
485 | Perl data structure in memory at one time, it does allow you to parse a |
474 | CBOR stream incrementally, using a similar to using "decode_prefix" to see |
486 | CBOR stream incrementally, using a similar to using "decode_prefix" to see |
475 | if a full CBOR object is available, but is much more efficient. |
487 | if a full CBOR object is available, but is much more efficient. |
476 | |
488 | |
477 | It basically works by parsing as much of a CBOR string as possible - if |
489 | It basically works by parsing as much of a CBOR string as possible - if |
478 | the CBOR data is not complete yet, the pasrer will remember where it was, |
490 | the CBOR data is not complete yet, the parser will remember where it was, |
479 | to be able to restart when more data has been accumulated. Once enough |
491 | to be able to restart when more data has been accumulated. Once enough |
480 | data is available to either decode a complete CBOR value or raise an |
492 | data is available to either decode a complete CBOR value or raise an |
481 | error, a real decode will be attempted. |
493 | error, a real decode will be attempted. |
482 | |
494 | |
483 | A typical use case would be a network protocol that consists of sending |
495 | A typical use case would be a network protocol that consists of sending |
… | |
… | |
635 | create such objects. |
647 | create such objects. |
636 | |
648 | |
637 | =item Types::Serialiser::true, Types::Serialiser::false, Types::Serialiser::error |
649 | =item Types::Serialiser::true, Types::Serialiser::false, Types::Serialiser::error |
638 | |
650 | |
639 | These special values become CBOR true, CBOR false and CBOR undefined |
651 | These special values become CBOR true, CBOR false and CBOR undefined |
640 | values, respectively. You can also use C<\1>, C<\0> and C<\undef> directly |
652 | values, respectively. |
641 | if you want. |
|
|
642 | |
653 | |
643 | =item other blessed objects |
654 | =item other blessed objects |
644 | |
655 | |
645 | Other blessed objects are serialised via C<TO_CBOR> or C<FREEZE>. See |
656 | Other blessed objects are serialised via C<TO_CBOR> or C<FREEZE>. See |
646 | L<TAG HANDLING AND EXTENSIONS> for specific classes handled by this |
657 | L<TAG HANDLING AND EXTENSIONS> for specific classes handled by this |