… | |
… | |
247 | the standard CBOR way. |
247 | the standard CBOR way. |
248 | |
248 | |
249 | This option does not affect C<decode> in any way - string references will |
249 | This option does not affect C<decode> in any way - string references will |
250 | always be decoded properly if present. |
250 | always be decoded properly if present. |
251 | |
251 | |
|
|
252 | =item $cbor = $cbor->text_keys ([$enable]) |
|
|
253 | |
|
|
254 | =item $enabled = $cbor->get_text_keys |
|
|
255 | |
|
|
256 | If C<$enabled> is true (or missing), then C<encode> will encode all |
|
|
257 | perl hash keys as CBOR text strings/UTF-8 string, upgrading them as needed. |
|
|
258 | |
|
|
259 | If C<$enable> is false (the default), then C<encode> will encode hash keys |
|
|
260 | normally - upgraded perl strings (strings internally encoded as UTF-8) as |
|
|
261 | CBOR text strings, and downgraded perl strings as CBOR byte strings. |
|
|
262 | |
|
|
263 | This option does not affect C<decode> in any way. |
|
|
264 | |
|
|
265 | This option is useful for interoperability with CBOR decoders that don't |
|
|
266 | treat byte strings as a form of text. It is especially useful as Perl |
|
|
267 | gives very little control over hash keys. |
|
|
268 | |
|
|
269 | Enabling this option can be slow, as all downgraded hash keys that are |
|
|
270 | encoded need to be scanned and converted to UTF-8. |
|
|
271 | |
|
|
272 | =item $cbor = $cbor->text_strings ([$enable]) |
|
|
273 | |
|
|
274 | =item $enabled = $cbor->get_text_strings |
|
|
275 | |
|
|
276 | This option works similar to C<text_keys>, above, but works on all strings |
|
|
277 | (including hash keys), so C<text_keys> has no further effect after |
|
|
278 | enabling C<text_strings>. |
|
|
279 | |
|
|
280 | If C<$enabled> is true (or missing), then C<encode> will encode all perl |
|
|
281 | strings as CBOR text strings/UTF-8 strings, upgrading them as needed. |
|
|
282 | |
|
|
283 | If C<$enable> is false (the default), then C<encode> will encode strings |
|
|
284 | normally (but see C<text_keys>) - upgraded perl strings (strings |
|
|
285 | internally encoded as UTF-8) as CBOR text strings, and downgraded perl |
|
|
286 | strings as CBOR byte strings. |
|
|
287 | |
|
|
288 | This option does not affect C<decode> in any way. |
|
|
289 | |
|
|
290 | This option has similar advantages and disadvantages as C<text_keys>. In |
|
|
291 | addition, this option effectively removes the ability to encode byte |
|
|
292 | strings, which might break some C<FREEZE> and C<TO_CBOR> methods that rely |
|
|
293 | on this, such as bignum encoding, so this option is mainly useful for very |
|
|
294 | simple data. |
|
|
295 | |
252 | =item $cbor = $cbor->validate_utf8 ([$enable]) |
296 | =item $cbor = $cbor->validate_utf8 ([$enable]) |
253 | |
297 | |
254 | =item $enabled = $cbor->get_validate_utf8 |
298 | =item $enabled = $cbor->get_validate_utf8 |
255 | |
299 | |
256 | If C<$enable> is true (or missing), then C<decode> will validate that |
300 | If C<$enable> is true (or missing), then C<decode> will validate that |
… | |
… | |
261 | The concept of "valid UTF-8" used is perl's concept, which is a superset |
305 | The concept of "valid UTF-8" used is perl's concept, which is a superset |
262 | of the official UTF-8. |
306 | of the official UTF-8. |
263 | |
307 | |
264 | If C<$enable> is false (the default), then C<decode> will blindly accept |
308 | If C<$enable> is false (the default), then C<decode> will blindly accept |
265 | UTF-8 data, marking them as valid UTF-8 in the resulting data structure |
309 | UTF-8 data, marking them as valid UTF-8 in the resulting data structure |
266 | regardless of whether thats true or not. |
310 | regardless of whether that's true or not. |
267 | |
311 | |
268 | Perl isn't too happy about corrupted UTF-8 in strings, but should |
312 | Perl isn't too happy about corrupted UTF-8 in strings, but should |
269 | generally not crash or do similarly evil things. Extensions might be not |
313 | generally not crash or do similarly evil things. Extensions might be not |
270 | so forgiving, so it's recommended to turn on this setting if you receive |
314 | so forgiving, so it's recommended to turn on this setting if you receive |
271 | untrusted CBOR. |
315 | untrusted CBOR. |
… | |
… | |
663 | "$self" # encode url string |
707 | "$self" # encode url string |
664 | } |
708 | } |
665 | |
709 | |
666 | sub URI::THAW { |
710 | sub URI::THAW { |
667 | my ($class, $serialiser, $uri) = @_; |
711 | my ($class, $serialiser, $uri) = @_; |
668 | |
|
|
669 | $class->new ($uri) |
712 | $class->new ($uri) |
670 | } |
713 | } |
671 | |
714 | |
672 | Unlike C<TO_CBOR>, multiple values can be returned by C<FREEZE>. For |
715 | Unlike C<TO_CBOR>, multiple values can be returned by C<FREEZE>. For |
673 | example, a C<FREEZE> method that returns "type", "id" and "variant" values |
716 | example, a C<FREEZE> method that returns "type", "id" and "variant" values |
… | |
… | |
804 | additional tags (such as base64url). |
847 | additional tags (such as base64url). |
805 | |
848 | |
806 | =head2 ENFORCED TAGS |
849 | =head2 ENFORCED TAGS |
807 | |
850 | |
808 | These tags are always handled when decoding, and their handling cannot be |
851 | These tags are always handled when decoding, and their handling cannot be |
809 | overriden by the user. |
852 | overridden by the user. |
810 | |
853 | |
811 | =over 4 |
854 | =over 4 |
812 | |
855 | |
813 | =item 26 (perl-object, L<http://cbor.schmorp.de/perl-object>) |
856 | =item 26 (perl-object, L<http://cbor.schmorp.de/perl-object>) |
814 | |
857 | |
… | |
… | |
842 | encoded, however, when C<pack_strings> is enabled. |
885 | encoded, however, when C<pack_strings> is enabled. |
843 | |
886 | |
844 | =item 22098 (indirection, L<http://cbor.schmorp.de/indirection>) |
887 | =item 22098 (indirection, L<http://cbor.schmorp.de/indirection>) |
845 | |
888 | |
846 | This tag is automatically generated when a reference are encountered (with |
889 | This tag is automatically generated when a reference are encountered (with |
847 | the exception of hash and array refernces). It is converted to a reference |
890 | the exception of hash and array references). It is converted to a reference |
848 | when decoding. |
891 | when decoding. |
849 | |
892 | |
850 | =item 55799 (self-describe CBOR, RFC 7049) |
893 | =item 55799 (self-describe CBOR, RFC 7049) |
851 | |
894 | |
852 | This value is not generated on encoding (unless explicitly requested by |
895 | This value is not generated on encoding (unless explicitly requested by |
… | |
… | |
855 | =back |
898 | =back |
856 | |
899 | |
857 | =head2 NON-ENFORCED TAGS |
900 | =head2 NON-ENFORCED TAGS |
858 | |
901 | |
859 | These tags have default filters provided when decoding. Their handling can |
902 | These tags have default filters provided when decoding. Their handling can |
860 | be overriden by changing the C<%CBOR::XS::FILTER> entry for the tag, or by |
903 | be overridden by changing the C<%CBOR::XS::FILTER> entry for the tag, or by |
861 | providing a custom C<filter> callback when decoding. |
904 | providing a custom C<filter> callback when decoding. |
862 | |
905 | |
863 | When they result in decoding into a specific Perl class, the module |
906 | When they result in decoding into a specific Perl class, the module |
864 | usually provides a corresponding C<TO_CBOR> method as well. |
907 | usually provides a corresponding C<TO_CBOR> method as well. |
865 | |
908 | |