--- CBOR-XS/XS.pm 2013/11/28 12:11:06 1.26 +++ CBOR-XS/XS.pm 2013/11/28 15:43:24 1.27 @@ -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