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

Comparing CBOR-XS/README (file contents):
Revision 1.21 by root, Tue Dec 8 08:29:44 2020 UTC vs.
Revision 1.22 by root, Thu Oct 21 01:14:58 2021 UTC

86 but configures the coder object to be safe to use with untrusted 86 but configures the coder object to be safe to use with untrusted
87 data. Currently, this is equivalent to: 87 data. Currently, this is equivalent to:
88 88
89 my $cbor = CBOR::XS 89 my $cbor = CBOR::XS
90 ->new 90 ->new
91 ->validate_utf8
91 ->forbid_objects 92 ->forbid_objects
92 ->filter (\&CBOR::XS::safe_filter) 93 ->filter (\&CBOR::XS::safe_filter)
93 ->max_size (1e8); 94 ->max_size (1e8);
94 95
95 But is more future proof (it is better to crash because of a change 96 But is more future proof (it is better to crash because of a change
616 than IEEE double to represent numerical values are supported, but 617 than IEEE double to represent numerical values are supported, but
617 might suffer loss of precision. 618 might suffer loss of precision.
618 619
619 TYPE CASTS 620 TYPE CASTS
620 EXPERIMENTAL: As an experimental extension, "CBOR::XS" allows you to 621 EXPERIMENTAL: As an experimental extension, "CBOR::XS" allows you to
621 force specific cbor types to be used when encoding. That allows you to 622 force specific CBOR types to be used when encoding. That allows you to
622 encode types not normally accessible (e.g. half floats) as well as force 623 encode types not normally accessible (e.g. half floats) as well as force
623 string types even when "text_strings" is in effect. 624 string types even when "text_strings" is in effect.
624 625
625 Type forcing is done by calling a special "cast" function which keeps a 626 Type forcing is done by calling a special "cast" function which keeps a
626 copy of the value and returns a new value that can be handed over to any 627 copy of the value and returns a new value that can be handed over to any
627 CBOR encoder function. 628 CBOR encoder function.
628 629
629 The following casts are currently available (all of which are unary 630 The following casts are currently available (all of which are unary
630 operators): 631 operators, that is, have a prototype of "$"):
631 632
632 CBOR::XS::as_int $value 633 CBOR::XS::as_int $value
633 Forces the value to be encoded as some form of (basic, not bignum) 634 Forces the value to be encoded as some form of (basic, not bignum)
634 integer type. 635 integer type.
635 636
658 659
659 CBOR::XS::as_float64 $value 660 CBOR::XS::as_float64 $value
660 Forces double-float (IEEE 754 binary64) encoding of the given value. 661 Forces double-float (IEEE 754 binary64) encoding of the given value.
661 662
662 CBOR::XS::as_cbor $cbor_text 663 CBOR::XS::as_cbor $cbor_text
663 Not a type cast per-se, this type cast forces the argument to eb 664 Not a type cast per-se, this type cast forces the argument to be
664 encoded as-is. This can be used to embed pre-encoded CBOR data. 665 encoded as-is. This can be used to embed pre-encoded CBOR data.
665 666
666 Note that no checking on the validity of the $cbor_text is done - 667 Note that no checking on the validity of the $cbor_text is done -
667 it's the callers responsibility to correctly encode values. 668 it's the callers responsibility to correctly encode values.
668 669
669 CBOR::XS::as_map [key => value...] 670 CBOR::XS::as_map [key => value...]
670 Treat the array reference as key value pairs and output a CBOR map. 671 Treat the array reference as key value pairs and output a CBOR map.
671 This allows you to generate CBOR maps with arbitrary key types (or, 672 This allows you to generate CBOR maps with arbitrary key types (or,
672 if you don't care about semantics, duplicate keys or prairs in a 673 if you don't care about semantics, duplicate keys or pairs in a
673 custom order), which is otherwise hard to do with Perl. 674 custom order), which is otherwise hard to do with Perl.
674 675
675 The single argument must be an array reference with an even number 676 The single argument must be an array reference with an even number
676 of elements. 677 of elements.
678
679 Note that only the reference to the array is copied, the array
680 itself is not. Modifications done to the array before calling an
681 encoding function will be reflected in the encoded output.
677 682
678 Example: encode a CBOR map with a string and an integer as keys. 683 Example: encode a CBOR map with a string and an integer as keys.
679 684
680 encode_cbor CBOR::XS::as_map [string => "value", 5 => "value"] 685 encode_cbor CBOR::XS::as_map [string => "value", 5 => "value"]
681 686

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines