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

Comparing CBOR-XS/XS.pm (file contents):
Revision 1.26 by root, Thu Nov 28 12:11:06 2013 UTC vs.
Revision 1.27 by root, Thu Nov 28 15:43:24 2013 UTC

323CBOR integers become (numeric) perl scalars. On perls without 64 bit 323CBOR integers become (numeric) perl scalars. On perls without 64 bit
324support, 64 bit integers will be truncated or otherwise corrupted. 324support, 64 bit integers will be truncated or otherwise corrupted.
325 325
326=item byte strings 326=item byte strings
327 327
328Byte strings will become octet strings in Perl (the byte values 0..255 328Byte strings will become octet strings in Perl (the Byte values 0..255
329will simply become characters of the same value in Perl). 329will simply become characters of the same value in Perl).
330 330
331=item UTF-8 strings 331=item UTF-8 strings
332 332
333UTF-8 strings in CBOR will be decoded, i.e. the UTF-8 octets will be 333UTF-8 strings in CBOR will be decoded, i.e. the UTF-8 octets will be
424 # dump as number 424 # dump as number
425 encode_cbor [2] # yields [2] 425 encode_cbor [2] # yields [2]
426 encode_cbor [-3.0e17] # yields [-3e+17] 426 encode_cbor [-3.0e17] # yields [-3e+17]
427 my $value = 5; encode_cbor [$value] # yields [5] 427 my $value = 5; encode_cbor [$value] # yields [5]
428 428
429 # used as string, so dump as string 429 # used as string, so dump as string (either byte or text)
430 print $value; 430 print $value;
431 encode_cbor [$value] # yields ["5"] 431 encode_cbor [$value] # yields ["5"]
432 432
433 # undef becomes null 433 # undef becomes null
434 encode_cbor [undef] # yields [null] 434 encode_cbor [undef] # yields [null]
437 437
438 my $x = 3.1; # some variable containing a number 438 my $x = 3.1; # some variable containing a number
439 "$x"; # stringified 439 "$x"; # stringified
440 $x .= ""; # another, more awkward way to stringify 440 $x .= ""; # another, more awkward way to stringify
441 print $x; # perl does it for you, too, quite often 441 print $x; # perl does it for you, too, quite often
442
443You can force whether a string ie encoded as byte or text string by using
444C<utf8::upgrade> and C<utf8::downgrade>):
445
446 utf8::upgrade $x; # encode $x as text string
447 utf8::downgrade $x; # encode $x as byte string
448
449Perl doesn't define what operations up- and downgrade strings, so if the
450difference between byte and text is important, you should up- or downgrade
451your string as late as possible before encoding.
442 452
443You can force the type to be a CBOR number by numifying it: 453You can force the type to be a CBOR number by numifying it:
444 454
445 my $x = "3"; # some variable containing a string 455 my $x = "3"; # some variable containing a string
446 $x += 0; # numify it, ensuring it will be dumped as a number 456 $x += 0; # numify it, ensuring it will be dumped as a number

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines