ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/XS.pm
(Generate patch)

Comparing CBOR-XS/XS.pm (file contents):
Revision 1.18 by root, Sun Nov 17 05:26:14 2013 UTC vs.
Revision 1.19 by root, Wed Nov 20 01:09:46 2013 UTC

157If no argument is given, the limit check will be deactivated (same as when 157If no argument is given, the limit check will be deactivated (same as when
158C<0> is specified). 158C<0> is specified).
159 159
160See SECURITY CONSIDERATIONS, below, for more info on why this is useful. 160See 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
166If C<$enable> is true (or missing), then C<encode> will I<not> throw an
167exception when it encounters values it cannot represent in CBOR (for
168example, filehandles) but instead will encode a CBOR C<error> value.
169
170If C<$enable> is false (the default), then C<encode> will throw an
171exception when it encounters anything it cannot encode as CBOR.
172
173This option does not affect C<decode> in any way, and it is recommended to
174leave 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
180If C<$enable> is true (or missing), then C<encode> will not double-encode
181values that have been seen before (e.g. when the same object, such as an
182array, is referenced multiple times), but instead will emit a reference to
183the earlier value.
184
185This means that such values will only be encoded once, and will not result
186in a deep cloning of the value on decode, in decoders supporting the value
187sharing extension.
188
189Detecting shared values incurs a runtime overhead when values are encoded
190that have a reference counter large than one, and might unnecessarily
191increase the encoded size, as potentially shared values are encode as
192sharable whether or not they are actually shared.
193
194At the moment, all shared values will be detected, even weird and unusual
195cases, such as an array with multiple "copies" of the I<same> scalar,
196which are hard but not impossible to create in Perl (L<Storable> for
197example doesn't handle these cases). If this turns out ot be a performance
198issue then future versions might limit the shared value detection to
199references only.
200
201If C<$enable> is false (the default), then C<encode> will encode
202exception when it encounters anything it cannot encode as CBOR.
203
204This option does not affect C<decode> in any way - shared values and
205references will always be decoded properly if present. It is recommended
206to leave it off unless you know your communications partner supports the
207value 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
164Converts the given Perl data structure (a scalar value) to its CBOR 211Converts the given Perl data structure (a scalar value) to its CBOR
165representation. 212representation.
166 213
551Wrap CBOR data in CBOR: 598Wrap 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
606This section describes how this module handles specific tagged values and
607extensions. If a tag is not mentioned here, then the default handling
608applies (creating a CBOR::XS::Tagged object on decoding, and only encoding
609the tag when explicitly requested).
610
611Future versions of this module reserve the right to special case
612additional tags (such as bigfloat or base64url).
613
614=over 4
615
616=item <unassigned> (perl-object, L<http://cbor.schmorp.de/perl-object>)
617
618These tags are automatically created for serialisable objects using the
619C<FREEZE/THAW> methods (the L<Types::Serialier> object serialisation
620protocol).
621
622=item <unassigned>, <unassigned> (sharable, sharedref, L <http://cbor.schmorp.de/value-sharing>)
623
624These tags are automatically decoded when encountered, resulting in
625shared values in the decoded object. They are only encoded, however, when
626C<allow_sharable> is enabled.
627
628=item 22098 (indirection, L<http://cbor.schmorp.de/indirection>)
629
630This tag is automatically generated when a reference are encountered (with
631the exception of hash and array refernces). It is converted to a reference
632when decoding.
633
634=item 55799 (self-describe CBOR, RFC 7049)
635
636This value is not generated on encoding (unless explicitly requested by
637the 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
559CBOR is supposed to implement a superset of the JSON data model, and is, 644CBOR is supposed to implement a superset of the JSON data model, and is,
560with some coercion, able to represent all JSON texts (something that other 645with some coercion, able to represent all JSON texts (something that other

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines