… | |
… | |
453 | This string is available as C<$CBOR::XS::MAGIC>. This module does not |
453 | This string is available as C<$CBOR::XS::MAGIC>. This module does not |
454 | prepend this string tot he CBOR data it generates, but it will ignroe it |
454 | prepend this string tot he CBOR data it generates, but it will ignroe it |
455 | if present, so users can prepend this string as a "file type" indicator as |
455 | if present, so users can prepend this string as a "file type" indicator as |
456 | required. |
456 | required. |
457 | |
457 | |
|
|
458 | |
|
|
459 | =head1 THE CBOR::XS::Tagged CLASS |
|
|
460 | |
|
|
461 | CBOR has the concept of tagged values - any CBOR value can be tagged with |
|
|
462 | a numeric 64 bit number, which are centrally administered. |
|
|
463 | |
|
|
464 | C<CBOR::XS> handles a few tags internally when en- or decoding. You can |
|
|
465 | also create tags yourself by encoding C<CBOR::XS::Tagged> objects, and the |
|
|
466 | decoder will create C<CBOR::XS::Tagged> objects itself when it hits an |
|
|
467 | unknown tag. |
|
|
468 | |
|
|
469 | These objects are simply blessed array references - the first member of |
|
|
470 | the array being the numerical tag, the second being the value. |
|
|
471 | |
|
|
472 | You can interact with C<CBOR::XS::Tagged> objects in the following ways: |
|
|
473 | |
|
|
474 | =over 4 |
|
|
475 | |
|
|
476 | =item $tagged = CBOR::XS::tag $tag, $value |
|
|
477 | |
|
|
478 | This function(!) creates a new C<CBOR::XS::Tagged> object using the given |
|
|
479 | C<$tag> (0..2**64-1) to tag the given C<$value> (which can be any Perl |
|
|
480 | value that can be encoded in CBOR, including serialisable Perl objects and |
|
|
481 | C<CBOR::XS::Tagged> objects). |
|
|
482 | |
|
|
483 | =item $tagged->[0] |
|
|
484 | |
|
|
485 | =item $tagged->[0] = $new_tag |
|
|
486 | |
|
|
487 | =item $tag = $tagged->tag |
|
|
488 | |
|
|
489 | =item $new_tag = $tagged->tag ($new_tag) |
|
|
490 | |
|
|
491 | Access/mutate the tag. |
|
|
492 | |
|
|
493 | =item $tagged->[1] |
|
|
494 | |
|
|
495 | =item $tagged->[1] = $new_value |
|
|
496 | |
|
|
497 | =item $value = $tagged->value |
|
|
498 | |
|
|
499 | =item $new_value = $tagged->value ($new_value) |
|
|
500 | |
|
|
501 | Access/mutate the tagged value. |
|
|
502 | |
|
|
503 | =back |
|
|
504 | |
|
|
505 | =cut |
|
|
506 | |
|
|
507 | sub tag($$) { |
|
|
508 | bless [@_], CBOR::XS::Tagged::; |
|
|
509 | } |
|
|
510 | |
|
|
511 | sub CBOR::XS::Tagged::tag { |
|
|
512 | $_[0][0] = $_[1] if $#_; |
|
|
513 | $_[0][0] |
|
|
514 | } |
|
|
515 | |
|
|
516 | sub CBOR::XS::Tagged::value { |
|
|
517 | $_[0][1] = $_[1] if $#_; |
|
|
518 | $_[0][1] |
|
|
519 | } |
458 | |
520 | |
459 | =head1 CBOR and JSON |
521 | =head1 CBOR and JSON |
460 | |
522 | |
461 | CBOR is supposed to implement a superset of the JSON data model, and is, |
523 | CBOR is supposed to implement a superset of the JSON data model, and is, |
462 | with some coercion, able to represent all JSON texts (something that other |
524 | with some coercion, able to represent all JSON texts (something that other |