--- CBOR-XS/XS.pm 2013/11/28 12:08:07 1.25 +++ CBOR-XS/XS.pm 2013/11/28 15:43:24 1.27 @@ -193,7 +193,7 @@ It is recommended to leave it off unless you know your communication partner supports the value sharing extensions to CBOR -(http://cbor.schmorp.de/value-sharing), as without decoder support, the +(L), as without decoder support, the resulting data structure might be unusable. Detecting shared values incurs a runtime overhead when values are encoded @@ -226,7 +226,7 @@ It is recommended to leave it off unless you know your communications partner supports the stringref extension to CBOR -(http://cbor.schmorp.de/stringref), as without decoder support, the +(L), as without decoder support, the resulting data structure might not be usable. If C<$enable> is false (the default), then C will encode strings @@ -325,7 +325,7 @@ =item byte strings -Byte strings will become octet strings in Perl (the byte values 0..255 +Byte strings will become octet strings in Perl (the Byte values 0..255 will simply become characters of the same value in Perl). =item UTF-8 strings @@ -426,7 +426,7 @@ encode_cbor [-3.0e17] # yields [-3e+17] my $value = 5; encode_cbor [$value] # yields [5] - # used as string, so dump as string + # used as string, so dump as string (either byte or text) print $value; encode_cbor [$value] # yields ["5"] @@ -440,6 +440,16 @@ $x .= ""; # another, more awkward way to stringify print $x; # perl does it for you, too, quite often +You can force whether a string ie encoded as byte or text string by using +C and C): + + utf8::upgrade $x; # encode $x as text string + utf8::downgrade $x; # encode $x as byte string + +Perl doesn't define what operations up- and downgrade strings, so if the +difference between byte and text is important, you should up- or downgrade +your string as late as possible before encoding. + You can force the type to be a CBOR number by numifying it: my $x = "3"; # some variable containing a string @@ -681,19 +691,19 @@ =over 4 -=item (perl-object, L) +=item 26 (perl-object, L) These tags are automatically created (and decoded) for serialisable objects using the C methods (the L object serialisation protocol). See L for details. -=item , (sharable, sharedref, L ) +=item 28, 29 (sharable, sharedref, L ) These tags are automatically decoded when encountered, resulting in shared values in the decoded object. They are only encoded, however, when C is enabled. -=item , (stringref-namespace, stringref, L ) +=item 256, 25 (stringref-namespace, stringref, L ) These tags are automatically decoded when encountered. They are only encoded, however, when C is enabled.