… | |
… | |
157 | If no argument is given, the limit check will be deactivated (same as when |
157 | If no argument is given, the limit check will be deactivated (same as when |
158 | C<0> is specified). |
158 | C<0> is specified). |
159 | |
159 | |
160 | See SECURITY CONSIDERATIONS, below, for more info on why this is useful. |
160 | See SECURITY CONSIDERATIONS, below, for more info on why this is useful. |
161 | |
161 | |
|
|
162 | =item $cbor = $cbor->allow_unknown ([$enable]) |
|
|
163 | |
|
|
164 | =item $enabled = $cbor->get_allow_unknown |
|
|
165 | |
|
|
166 | If C<$enable> is true (or missing), then C<encode> will I<not> throw an |
|
|
167 | exception when it encounters values it cannot represent in CBOR (for |
|
|
168 | example, filehandles) but instead will encode a CBOR C<error> value. |
|
|
169 | |
|
|
170 | If C<$enable> is false (the default), then C<encode> will throw an |
|
|
171 | exception when it encounters anything it cannot encode as CBOR. |
|
|
172 | |
|
|
173 | This option does not affect C<decode> in any way, and it is recommended to |
|
|
174 | leave it off unless you know your communications partner. |
|
|
175 | |
|
|
176 | =item $cbor = $cbor->allow_sharable ([$enable]) |
|
|
177 | |
|
|
178 | =item $enabled = $cbor->get_allow_sharable |
|
|
179 | |
|
|
180 | If C<$enable> is true (or missing), then C<encode> will not double-encode |
|
|
181 | values that have been seen before (e.g. when the same object, such as an |
|
|
182 | array, is referenced multiple times), but instead will emit a reference to |
|
|
183 | the earlier value. |
|
|
184 | |
|
|
185 | This means that such values will only be encoded once, and will not result |
|
|
186 | in a deep cloning of the value on decode, in decoders supporting the value |
|
|
187 | sharing extension. |
|
|
188 | |
|
|
189 | Detecting shared values incurs a runtime overhead when values are encoded |
|
|
190 | that have a reference counter large than one, and might unnecessarily |
|
|
191 | increase the encoded size, as potentially shared values are encode as |
|
|
192 | sharable whether or not they are actually shared. |
|
|
193 | |
|
|
194 | At the moment, all shared values will be detected, even weird and unusual |
|
|
195 | cases, such as an array with multiple "copies" of the I<same> scalar, |
|
|
196 | which are hard but not impossible to create in Perl (L<Storable> for |
|
|
197 | example doesn't handle these cases). If this turns out ot be a performance |
|
|
198 | issue then future versions might limit the shared value detection to |
|
|
199 | references only. |
|
|
200 | |
|
|
201 | If C<$enable> is false (the default), then C<encode> will encode |
|
|
202 | exception when it encounters anything it cannot encode as CBOR. |
|
|
203 | |
|
|
204 | This option does not affect C<decode> in any way - shared values and |
|
|
205 | references will always be decoded properly if present. It is recommended |
|
|
206 | to leave it off unless you know your communications partner supports the |
|
|
207 | value sharing extensions to CBOR (http://cbor.schmorp.de/value-sharing). |
|
|
208 | |
162 | =item $cbor_data = $cbor->encode ($perl_scalar) |
209 | =item $cbor_data = $cbor->encode ($perl_scalar) |
163 | |
210 | |
164 | Converts the given Perl data structure (a scalar value) to its CBOR |
211 | Converts the given Perl data structure (a scalar value) to its CBOR |
165 | representation. |
212 | representation. |
166 | |
213 | |
… | |
… | |
455 | =head1 MAGIC HEADER |
502 | =head1 MAGIC HEADER |
456 | |
503 | |
457 | There is no way to distinguish CBOR from other formats |
504 | There is no way to distinguish CBOR from other formats |
458 | programmatically. To make it easier to distinguish CBOR from other |
505 | programmatically. To make it easier to distinguish CBOR from other |
459 | formats, the CBOR specification has a special "magic string" that can be |
506 | formats, the CBOR specification has a special "magic string" that can be |
460 | prepended to any CBOR string without changing it's meaning. |
507 | prepended to any CBOR string without changing its meaning. |
461 | |
508 | |
462 | This string is available as C<$CBOR::XS::MAGIC>. This module does not |
509 | This string is available as C<$CBOR::XS::MAGIC>. This module does not |
463 | prepend this string tot he CBOR data it generates, but it will ignroe it |
510 | prepend this string to the CBOR data it generates, but it will ignore it |
464 | if present, so users can prepend this string as a "file type" indicator as |
511 | if present, so users can prepend this string as a "file type" indicator as |
465 | required. |
512 | required. |
466 | |
513 | |
467 | |
514 | |
468 | =head1 THE CBOR::XS::Tagged CLASS |
515 | =head1 THE CBOR::XS::Tagged CLASS |
… | |
… | |
551 | Wrap CBOR data in CBOR: |
598 | Wrap CBOR data in CBOR: |
552 | |
599 | |
553 | my $cbor_cbor = encode_cbor |
600 | my $cbor_cbor = encode_cbor |
554 | CBOR::XS::tag 24, |
601 | CBOR::XS::tag 24, |
555 | encode_cbor [1, 2, 3]; |
602 | encode_cbor [1, 2, 3]; |
|
|
603 | |
|
|
604 | =head1 TAG HANDLING AND EXTENSIONS |
|
|
605 | |
|
|
606 | This section describes how this module handles specific tagged values and |
|
|
607 | extensions. If a tag is not mentioned here, then the default handling |
|
|
608 | applies (creating a CBOR::XS::Tagged object on decoding, and only encoding |
|
|
609 | the tag when explicitly requested). |
|
|
610 | |
|
|
611 | Future versions of this module reserve the right to special case |
|
|
612 | additional tags (such as bigfloat or base64url). |
|
|
613 | |
|
|
614 | =over 4 |
|
|
615 | |
|
|
616 | =item <unassigned> (perl-object, L<http://cbor.schmorp.de/perl-object>) |
|
|
617 | |
|
|
618 | These tags are automatically created for serialisable objects using the |
|
|
619 | C<FREEZE/THAW> methods (the L<Types::Serialier> object serialisation |
|
|
620 | protocol). |
|
|
621 | |
|
|
622 | =item <unassigned>, <unassigned> (sharable, sharedref, L <http://cbor.schmorp.de/value-sharing>) |
|
|
623 | |
|
|
624 | These tags are automatically decoded when encountered, resulting in |
|
|
625 | shared values in the decoded object. They are only encoded, however, when |
|
|
626 | C<allow_sharable> is enabled. |
|
|
627 | |
|
|
628 | =item 22098 (indirection, L<http://cbor.schmorp.de/indirection>) |
|
|
629 | |
|
|
630 | This tag is automatically generated when a reference are encountered (with |
|
|
631 | the exception of hash and array refernces). It is converted to a reference |
|
|
632 | when decoding. |
|
|
633 | |
|
|
634 | =item 55799 (self-describe CBOR, RFC 7049) |
|
|
635 | |
|
|
636 | This value is not generated on encoding (unless explicitly requested by |
|
|
637 | the user), and is simply ignored when decoding. |
|
|
638 | |
|
|
639 | =back |
|
|
640 | |
556 | |
641 | |
557 | =head1 CBOR and JSON |
642 | =head1 CBOR and JSON |
558 | |
643 | |
559 | CBOR is supposed to implement a superset of the JSON data model, and is, |
644 | CBOR is supposed to implement a superset of the JSON data model, and is, |
560 | with some coercion, able to represent all JSON texts (something that other |
645 | with some coercion, able to represent all JSON texts (something that other |