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.78 by root, Tue Dec 8 08:29:44 2020 UTC vs.
Revision 1.81 by root, Fri Dec 11 06:10:26 2020 UTC

704=back 704=back
705 705
706=head2 TYPE CASTS 706=head2 TYPE CASTS
707 707
708B<EXPERIMENTAL>: As an experimental extension, C<CBOR::XS> allows you to 708B<EXPERIMENTAL>: As an experimental extension, C<CBOR::XS> allows you to
709force specific cbor types to be used when encoding. That allows you to 709force specific CBOR types to be used when encoding. That allows you to
710encode types not normally accessible (e.g. half floats) as well as force 710encode types not normally accessible (e.g. half floats) as well as force
711string types even when C<text_strings> is in effect. 711string types even when C<text_strings> is in effect.
712 712
713Type forcing is done by calling a special "cast" function which keeps a 713Type forcing is done by calling a special "cast" function which keeps a
714copy of the value and returns a new value that can be handed over to any 714copy of the value and returns a new value that can be handed over to any
715CBOR encoder function. 715CBOR encoder function.
716 716
717The following casts are currently available (all of which are unary operators): 717The following casts are currently available (all of which are unary
718operators, 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
755 756
756Forces double-float (IEEE 754 binary64) encoding of the given value. 757Forces double-float (IEEE 754 binary64) encoding of the given value.
757 758
758=item CBOR::XS::as_cbor $cbor_text 759=item CBOR::XS::as_cbor $cbor_text
759 760
760Not a type cast per-se, this type cast forces the argument to eb encoded 761Not a type cast per-se, this type cast forces the argument to be encoded
761as-is. This can be used to embed pre-encoded CBOR data. 762as-is. This can be used to embed pre-encoded CBOR data.
762 763
763Note that no checking on the validity of the C<$cbor_text> is done - it's 764Note that no checking on the validity of the C<$cbor_text> is done - it's
764the callers responsibility to correctly encode values. 765the callers responsibility to correctly encode values.
765 766
766=item CBOR::XS::as_map [key => value...] 767=item CBOR::XS::as_map [key => value...]
767 768
768Treat the array reference as key value pairs and output a CBOR map. This 769Treat the array reference as key value pairs and output a CBOR map. This
769allows you to generate CBOR maps with arbitrary key types (or, if you 770allows you to generate CBOR maps with arbitrary key types (or, if you
770don't care about semantics, duplicate keys or prairs in a custom order), 771don't care about semantics, duplicate keys or pairs in a custom order),
771which is otherwise hard to do with Perl. 772which is otherwise hard to do with Perl.
772 773
773The single argument must be an array reference with an even number of 774The single argument must be an array reference with an even number of
774elements. 775elements.
776
777Note that only the reference to the array is copied, the array itself is
778not. Modifications done to the array before calling an encoding function
779will be reflected in the encoded output.
775 780
776Example: encode a CBOR map with a string and an integer as keys. 781Example: 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines