… | |
… | |
525 | ( |
525 | ( |
526 | sub { pack "(w/a*)*", @_ }, |
526 | sub { pack "(w/a*)*", @_ }, |
527 | sub { unpack "(w/a*)*", shift } |
527 | sub { unpack "(w/a*)*", shift } |
528 | ) |
528 | ) |
529 | |
529 | |
|
|
530 | =item json - C<$AnyEvent::Fork::RPC::CBOR_XS_SERIALISER> |
|
|
531 | |
|
|
532 | This serialiser creates CBOR::XS arrays - you have to make sure the |
|
|
533 | L<CBOR::XS> module is installed for this serialiser to work. It can be |
|
|
534 | beneficial for sharing when you preload the L<CBOR::XS> module in a template |
|
|
535 | process. |
|
|
536 | |
|
|
537 | L<CBOR::XS> is about as fast as the octet string serialiser, but supports |
|
|
538 | complex data structures (similar to JSON) and is faster than any of the |
|
|
539 | other serialisers. If you have the L<CBOR::XS> module available, it's the |
|
|
540 | best choice. |
|
|
541 | |
|
|
542 | Note that the CBOR::XS module supports some extensions to encode cyclic |
|
|
543 | and self-referencing data structures, which are not enabled. You need to |
|
|
544 | write your own serialiser to take advantage of these. |
|
|
545 | |
|
|
546 | Implementation: |
|
|
547 | |
|
|
548 | use CBOR::XS (); |
|
|
549 | ( |
|
|
550 | sub { CBOR::XS::encode_cbor \@_ }, |
|
|
551 | sub { @{ CBOR::XS::decode_cbor shift } } |
|
|
552 | ) |
|
|
553 | |
530 | =item json - C<$AnyEvent::Fork::RPC::JSON_SERIALISER> |
554 | =item json - C<$AnyEvent::Fork::RPC::JSON_SERIALISER> |
531 | |
555 | |
532 | This serialiser creates JSON arrays - you have to make sure the L<JSON> |
556 | This serialiser creates JSON arrays - you have to make sure the L<JSON> |
533 | module is installed for this serialiser to work. It can be beneficial for |
557 | module is installed for this serialiser to work. It can be beneficial for |
534 | sharing when you preload the L<JSON> module in a template process. |
558 | sharing when you preload the L<JSON> module in a template process. |
… | |
… | |
583 | examples. |
607 | examples. |
584 | |
608 | |
585 | =cut |
609 | =cut |
586 | |
610 | |
587 | our $STRING_SERIALISER = '(sub { pack "(w/a*)*", @_ }, sub { unpack "(w/a*)*", shift })'; |
611 | our $STRING_SERIALISER = '(sub { pack "(w/a*)*", @_ }, sub { unpack "(w/a*)*", shift })'; |
|
|
612 | our $CBOR_XS_SERIALISER = 'use CBOR::XS (); (sub { CBOR::XS::encode_cbor \@_ }, sub { @{ CBOR::XS::decode_cbor shift } })'; |
588 | our $JSON_SERIALISER = 'use JSON (); (sub { JSON::encode_json \@_ }, sub { @{ JSON::decode_json shift } })'; |
613 | our $JSON_SERIALISER = 'use JSON (); (sub { JSON::encode_json \@_ }, sub { @{ JSON::decode_json shift } })'; |
589 | our $STORABLE_SERIALISER = 'use Storable (); (sub { Storable::freeze \@_ }, sub { @{ Storable::thaw shift } })'; |
614 | our $STORABLE_SERIALISER = 'use Storable (); (sub { Storable::freeze \@_ }, sub { @{ Storable::thaw shift } })'; |
590 | our $NSTORABLE_SERIALISER = 'use Storable (); (sub { Storable::nfreeze \@_ }, sub { @{ Storable::thaw shift } })'; |
615 | our $NSTORABLE_SERIALISER = 'use Storable (); (sub { Storable::nfreeze \@_ }, sub { @{ Storable::thaw shift } })'; |
591 | |
616 | |
592 | sub run { |
617 | sub run { |
593 | my ($self, $function, %arg) = @_; |
618 | my ($self, $function, %arg) = @_; |