… | |
… | |
637 | Forces the value to be encoded as (UTF-8) text values. |
637 | Forces the value to be encoded as (UTF-8) text values. |
638 | |
638 | |
639 | CBOR::XS::as_bytes $value |
639 | CBOR::XS::as_bytes $value |
640 | Forces the value to be encoded as a (binary) string value. |
640 | Forces the value to be encoded as a (binary) string value. |
641 | |
641 | |
|
|
642 | Example: encode a perl string as binary even though "text_strings" |
|
|
643 | is in effect. |
|
|
644 | |
|
|
645 | CBOR::XS->new->text_strings->encode ([4, "text", CBOR::XS::bytes "bytevalue"]); |
|
|
646 | |
|
|
647 | CBOR::XS::as_bool $value |
|
|
648 | Converts a Perl boolean (which can be any kind of scalar) into a |
|
|
649 | CBOR boolean. Strictly the same, but shorter to write, than: |
|
|
650 | |
|
|
651 | $value ? Types::Serialiser::true : Types::Serialiser::false |
|
|
652 | |
642 | CBOR::XS::as_float16 $value |
653 | CBOR::XS::as_float16 $value |
643 | Forces half-float (IEEE 754 binary16) encoding of the given value. |
654 | Forces half-float (IEEE 754 binary16) encoding of the given value. |
644 | |
655 | |
645 | CBOR::XS::as_float32 $value |
656 | CBOR::XS::as_float32 $value |
646 | Forces single-float (IEEE 754 binary32) encoding of the given value. |
657 | Forces single-float (IEEE 754 binary32) encoding of the given value. |
647 | |
658 | |
648 | CBOR::XS::as_float64 $value |
659 | CBOR::XS::as_float64 $value |
649 | Forces double-float (IEEE 754 binary64) encoding of the given value. |
660 | Forces double-float (IEEE 754 binary64) encoding of the given value. |
650 | |
661 | |
651 | =item, CBOR::XS::as_cbor $cbor_text |
662 | CBOR::XS::as_cbor $cbor_text |
652 | |
|
|
653 | Bot a type cast per-se, this type cast forces the argument to eb |
663 | Not a type cast per-se, this type cast forces the argument to eb |
654 | encoded as-is. This can be used to embed pre-encoded CBOR data. |
664 | encoded as-is. This can be used to embed pre-encoded CBOR data. |
655 | |
665 | |
656 | Note that no checking on the validity of the $cbor_text is done - |
666 | Note that no checking on the validity of the $cbor_text is done - |
657 | it's the callers responsibility to correctly encode values. |
667 | it's the callers responsibility to correctly encode values. |
658 | |
668 | |
659 | Example: encode a perl string as binary even though "text_strings" is in |
669 | CBOR::XS::as_map [key => value...] |
660 | effect. |
670 | 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 | if you don't care about semantics, duplicate keys or prairs in a |
|
|
673 | custom order), which is otherwise hard to do with Perl. |
661 | |
674 | |
662 | CBOR::XS->new->text_strings->encode ([4, "text", CBOR::XS::bytes "bytevalue"]); |
675 | The single argument must be an array reference with an even number |
|
|
676 | of elements. |
|
|
677 | |
|
|
678 | Example: encode a CBOR map with a string and an integer as keys. |
|
|
679 | |
|
|
680 | encode_cbor CBOR::XS::as_map [string => "value", 5 => "value"] |
663 | |
681 | |
664 | OBJECT SERIALISATION |
682 | OBJECT SERIALISATION |
665 | This module implements both a CBOR-specific and the generic |
683 | This module implements both a CBOR-specific and the generic |
666 | Types::Serialier object serialisation protocol. The following |
684 | Types::Serialier object serialisation protocol. The following |
667 | subsections explain both methods. |
685 | subsections explain both methods. |