… | |
… | |
64 | |
64 | |
65 | package CBOR::XS; |
65 | package CBOR::XS; |
66 | |
66 | |
67 | use common::sense; |
67 | use common::sense; |
68 | |
68 | |
69 | our $VERSION = 1.71; |
69 | our $VERSION = 1.81; |
70 | our @ISA = qw(Exporter); |
70 | our @ISA = qw(Exporter); |
71 | |
71 | |
72 | our @EXPORT = qw(encode_cbor decode_cbor); |
72 | our @EXPORT = qw(encode_cbor decode_cbor); |
73 | |
73 | |
74 | use Exporter; |
74 | use Exporter; |
… | |
… | |
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 operators): |
718 | |
718 | |
719 | =over |
719 | =over |
720 | |
720 | |
|
|
721 | =item CBOR::XS::as_int $value |
|
|
722 | |
|
|
723 | Forces the value to be encoded as some form of (basic, not bignum) integer |
|
|
724 | type. |
|
|
725 | |
721 | =item CBOR::XS::as_text $value |
726 | =item CBOR::XS::as_text $value |
722 | |
727 | |
723 | Forces the value to be encoded as (UTF-8) text values. |
728 | Forces the value to be encoded as (UTF-8) text values. |
724 | |
729 | |
725 | =item CBOR::XS::as_bytes $value |
730 | =item CBOR::XS::as_bytes $value |
726 | |
731 | |
727 | Forces the value to be encoded as a (binary) string value. |
732 | Forces the value to be encoded as a (binary) string value. |
|
|
733 | |
|
|
734 | =item CBOR::XS::as_bool $value |
|
|
735 | |
|
|
736 | Converts a Perl boolean (which can be any kind of scalar) into a CBOR |
|
|
737 | boolean. Exactly the same, but shorter to write, than: |
|
|
738 | |
|
|
739 | $value ? Types::Serialiser::true : Types::Serialiser::false |
728 | |
740 | |
729 | =item CBOR::XS::as_float16 $value |
741 | =item CBOR::XS::as_float16 $value |
730 | |
742 | |
731 | Forces half-float (IEEE 754 binary16) encoding of the given value. |
743 | Forces half-float (IEEE 754 binary16) encoding of the given value. |
732 | |
744 | |
… | |
… | |
754 | CBOR::XS->new->text_strings->encode ([4, "text", CBOR::XS::bytes "bytevalue"]); |
766 | CBOR::XS->new->text_strings->encode ([4, "text", CBOR::XS::bytes "bytevalue"]); |
755 | |
767 | |
756 | =cut |
768 | =cut |
757 | |
769 | |
758 | sub CBOR::XS::as_cbor ($) { bless [$_[0], 0, undef], CBOR::XS::Tagged:: } |
770 | sub CBOR::XS::as_cbor ($) { bless [$_[0], 0, undef], CBOR::XS::Tagged:: } |
|
|
771 | sub CBOR::XS::as_int ($) { bless [$_[0], 1, undef], CBOR::XS::Tagged:: } |
759 | sub CBOR::XS::as_bytes ($) { bless [$_[0], 1, undef], CBOR::XS::Tagged:: } |
772 | sub CBOR::XS::as_bytes ($) { bless [$_[0], 2, undef], CBOR::XS::Tagged:: } |
760 | sub CBOR::XS::as_text ($) { bless [$_[0], 2, undef], CBOR::XS::Tagged:: } |
773 | sub CBOR::XS::as_text ($) { bless [$_[0], 3, undef], CBOR::XS::Tagged:: } |
761 | sub CBOR::XS::as_float16 ($) { bless [$_[0], 3, undef], CBOR::XS::Tagged:: } |
774 | sub CBOR::XS::as_float16 ($) { bless [$_[0], 4, undef], CBOR::XS::Tagged:: } |
762 | sub CBOR::XS::as_float32 ($) { bless [$_[0], 4, undef], CBOR::XS::Tagged:: } |
775 | sub CBOR::XS::as_float32 ($) { bless [$_[0], 5, undef], CBOR::XS::Tagged:: } |
763 | sub CBOR::XS::as_float64 ($) { bless [$_[0], 5, undef], CBOR::XS::Tagged:: } |
776 | sub CBOR::XS::as_float64 ($) { bless [$_[0], 6, undef], CBOR::XS::Tagged:: } |
|
|
777 | |
|
|
778 | sub CBOR::XS::as_bool ($) { $_[0] ? Types::Serialiser::true : Types::Serialiser::false } |
764 | |
779 | |
765 | =head2 OBJECT SERIALISATION |
780 | =head2 OBJECT SERIALISATION |
766 | |
781 | |
767 | This module implements both a CBOR-specific and the generic |
782 | This module implements both a CBOR-specific and the generic |
768 | L<Types::Serialier> object serialisation protocol. The following |
783 | L<Types::Serialier> object serialisation protocol. The following |