… | |
… | |
46 | In short, CBOR is a faster and very compact binary alternative to JSON, |
46 | In short, CBOR is a faster and very compact binary alternative to JSON, |
47 | with the added ability of supporting serialisation of Perl objects. (JSON |
47 | with the added ability of supporting serialisation of Perl objects. (JSON |
48 | often compresses better than CBOR though, so if you plan to compress the |
48 | often compresses better than CBOR though, so if you plan to compress the |
49 | data later you might want to compare both formats first). |
49 | data later you might want to compare both formats first). |
50 | |
50 | |
51 | To give you a general idea, with texts in the megabyte range, C<CBOR::XS> |
51 | To give you a general idea about speed, with texts in the megabyte range, |
52 | usually encodes roughly twice as fast as L<Storable> or L<JSON::XS> and |
52 | C<CBOR::XS> usually encodes roughly twice as fast as L<Storable> or |
53 | decodes about 15%-30% faster than those. The shorter the data, the worse |
53 | L<JSON::XS> and decodes about 15%-30% faster than those. The shorter the |
54 | L<Storable> performs in comparison. |
54 | data, the worse L<Storable> performs in comparison. |
|
|
55 | |
|
|
56 | As for compactness, C<CBOR::XS> encoded data structures are usually about |
|
|
57 | 20% smaller than the same data encoded as (compact) JSON or L<Storable>. |
55 | |
58 | |
56 | The primary goal of this module is to be I<correct> and the secondary goal |
59 | The primary goal of this module is to be I<correct> and the secondary goal |
57 | is to be I<fast>. To reach the latter goal it was written in C. |
60 | is to be I<fast>. To reach the latter goal it was written in C. |
58 | |
61 | |
59 | See MAPPING, below, on how CBOR::XS maps perl values to CBOR values and |
62 | See MAPPING, below, on how CBOR::XS maps perl values to CBOR values and |
… | |
… | |
63 | |
66 | |
64 | package CBOR::XS; |
67 | package CBOR::XS; |
65 | |
68 | |
66 | use common::sense; |
69 | use common::sense; |
67 | |
70 | |
68 | our $VERSION = 0.06; |
71 | our $VERSION = 0.08; |
69 | our @ISA = qw(Exporter); |
72 | our @ISA = qw(Exporter); |
70 | |
73 | |
71 | our @EXPORT = qw(encode_cbor decode_cbor); |
74 | our @EXPORT = qw(encode_cbor decode_cbor); |
72 | |
75 | |
73 | use Exporter; |
76 | use Exporter; |
… | |
… | |
452 | =head1 MAGIC HEADER |
455 | =head1 MAGIC HEADER |
453 | |
456 | |
454 | There is no way to distinguish CBOR from other formats |
457 | There is no way to distinguish CBOR from other formats |
455 | programmatically. To make it easier to distinguish CBOR from other |
458 | programmatically. To make it easier to distinguish CBOR from other |
456 | formats, the CBOR specification has a special "magic string" that can be |
459 | formats, the CBOR specification has a special "magic string" that can be |
457 | prepended to any CBOR string without changing it's meaning. |
460 | prepended to any CBOR string without changing its meaning. |
458 | |
461 | |
459 | This string is available as C<$CBOR::XS::MAGIC>. This module does not |
462 | This string is available as C<$CBOR::XS::MAGIC>. This module does not |
460 | prepend this string tot he CBOR data it generates, but it will ignroe it |
463 | prepend this string to the CBOR data it generates, but it will ignore it |
461 | if present, so users can prepend this string as a "file type" indicator as |
464 | if present, so users can prepend this string as a "file type" indicator as |
462 | required. |
465 | required. |
463 | |
466 | |
464 | |
467 | |
465 | =head1 THE CBOR::XS::Tagged CLASS |
468 | =head1 THE CBOR::XS::Tagged CLASS |