… | |
… | |
704 | =back |
704 | =back |
705 | |
705 | |
706 | =head2 TYPE CASTS |
706 | =head2 TYPE CASTS |
707 | |
707 | |
708 | B<EXPERIMENTAL>: As an experimental extension, C<CBOR::XS> allows you to |
708 | B<EXPERIMENTAL>: As an experimental extension, C<CBOR::XS> allows you to |
709 | force specific cbor types to be used when encoding. That allows you to |
709 | force specific CBOR types to be used when encoding. That allows you to |
710 | encode types not normally accessible (e.g. half floats) as well as force |
710 | encode types not normally accessible (e.g. half floats) as well as force |
711 | string types even when C<text_strings> is in effect. |
711 | string types even when C<text_strings> is in effect. |
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 |
… | |
… | |
756 | |
756 | |
757 | Forces double-float (IEEE 754 binary64) encoding of the given value. |
757 | Forces double-float (IEEE 754 binary64) encoding of the given value. |
758 | |
758 | |
759 | =item CBOR::XS::as_cbor $cbor_text |
759 | =item CBOR::XS::as_cbor $cbor_text |
760 | |
760 | |
761 | Not a type cast per-se, this type cast forces the argument to eb encoded |
761 | Not a type cast per-se, this type cast forces the argument to be encoded |
762 | as-is. This can be used to embed pre-encoded CBOR data. |
762 | as-is. This can be used to embed pre-encoded CBOR data. |
763 | |
763 | |
764 | Note that no checking on the validity of the C<$cbor_text> is done - it's |
764 | Note that no checking on the validity of the C<$cbor_text> is done - it's |
765 | the callers responsibility to correctly encode values. |
765 | the callers responsibility to correctly encode values. |
766 | |
766 | |
… | |
… | |
773 | |
773 | |
774 | 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 |
775 | elements. |
775 | elements. |
776 | |
776 | |
777 | Note that only the reference to the array is copied, the array itself is |
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 |
778 | not. Modifications done to the array before calling an encoding function |
779 | will be reflected in the encoded output. |
779 | will be reflected in the encoded output. |
780 | |
780 | |
781 | 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. |
782 | |
782 | |
783 | encode_cbor CBOR::XS::as_map [string => "value", 5 => "value"] |
783 | encode_cbor CBOR::XS::as_map [string => "value", 5 => "value"] |