… | |
… | |
712 | |
712 | |
713 | Type forcing is done by calling a special "cast" function which keeps a |
713 | Type forcing is done by calling a special "cast" function which keeps a |
714 | copy of the value and returns a new value that can be handed over to any |
714 | copy of the value and returns a new value that can be handed over to any |
715 | CBOR encoder function. |
715 | CBOR encoder function. |
716 | |
716 | |
717 | The following casts are currently available (all of which are unary operators): |
717 | The following casts are currently available (all of which are unary |
|
|
718 | operators, that is, have a prototype of C<$>): |
718 | |
719 | |
719 | =over |
720 | =over |
720 | |
721 | |
721 | =item CBOR::XS::as_int $value |
722 | =item CBOR::XS::as_int $value |
722 | |
723 | |
… | |
… | |
765 | |
766 | |
766 | =item CBOR::XS::as_map [key => value...] |
767 | =item CBOR::XS::as_map [key => value...] |
767 | |
768 | |
768 | Treat the array reference as key value pairs and output a CBOR map. This |
769 | Treat the array reference as key value pairs and output a CBOR map. This |
769 | allows you to generate CBOR maps with arbitrary key types (or, if you |
770 | allows you to generate CBOR maps with arbitrary key types (or, if you |
770 | don't care about semantics, duplicate keys or prairs in a custom order), |
771 | don't care about semantics, duplicate keys or pairs in a custom order), |
771 | which is otherwise hard to do with Perl. |
772 | which is otherwise hard to do with Perl. |
772 | |
773 | |
773 | The single argument must be an array reference with an even number of |
774 | The single argument must be an array reference with an even number of |
774 | elements. |
775 | elements. |
|
|
776 | |
|
|
777 | Note that only the reference to the array is copied, the array itself is |
|
|
778 | not. Modifications done to the array before calling an encoding fuinction |
|
|
779 | will be reflected in the encoded output. |
775 | |
780 | |
776 | Example: encode a CBOR map with a string and an integer as keys. |
781 | Example: encode a CBOR map with a string and an integer as keys. |
777 | |
782 | |
778 | encode_cbor CBOR::XS::as_map [string => "value", 5 => "value"] |
783 | encode_cbor CBOR::XS::as_map [string => "value", 5 => "value"] |
779 | |
784 | |