… | |
… | |
26 | |
26 | |
27 | use Scalar::Util (); |
27 | use Scalar::Util (); |
28 | use List::Util (); |
28 | use List::Util (); |
29 | use MIME::Base64 (); |
29 | use MIME::Base64 (); |
30 | |
30 | |
31 | use JSON::XS (); |
|
|
32 | use Digest::SHA3 (); |
31 | use Digest::SHA3 (); |
33 | use Digest::HMAC (); |
32 | use Digest::HMAC (); |
34 | |
33 | |
35 | use AnyEvent (); |
34 | use AnyEvent (); |
36 | use AnyEvent::Socket (); |
35 | use AnyEvent::Socket (); |
… | |
… | |
339 | |
338 | |
340 | my $framing = $self->{s_framing}; |
339 | my $framing = $self->{s_framing}; |
341 | my $hdl = $self->{hdl}; |
340 | my $hdl = $self->{hdl}; |
342 | my $push_write = $hdl->can ("push_write"); |
341 | my $push_write = $hdl->can ("push_write"); |
343 | |
342 | |
344 | if ($framing eq "json") { |
343 | if ($framing eq "cbor") { |
|
|
344 | require CBOR::XS; |
345 | $self->{send} = sub { |
345 | $self->{send} = sub { |
|
|
346 | $push_write->($hdl, CBOR::XS::encode_cbor ($_[0])); |
|
|
347 | }; |
|
|
348 | } elsif ($framing eq "json") { |
|
|
349 | require JSON::XS; |
|
|
350 | $self->{send} = sub { |
346 | $push_write->($hdl, JSON::XS::encode_json $_[0]); |
351 | $push_write->($hdl, JSON::XS::encode_json ($_[0])); |
347 | }; |
352 | }; |
348 | } else { |
353 | } else { |
349 | $self->{send} = sub { |
354 | $self->{send} = sub { |
350 | $push_write->($hdl, $framing => $_[0]); |
355 | $push_write->($hdl, $framing => $_[0]); |
351 | }; |
356 | }; |
… | |
… | |
358 | my $node = $self->{remote_node}; |
363 | my $node = $self->{remote_node}; |
359 | my $framing = $self->{r_framing}; |
364 | my $framing = $self->{r_framing}; |
360 | my $hdl = $self->{hdl}; |
365 | my $hdl = $self->{hdl}; |
361 | my $push_read = $hdl->can ("push_read"); |
366 | my $push_read = $hdl->can ("push_read"); |
362 | |
367 | |
|
|
368 | if ($framing eq "cbor") { |
|
|
369 | require CBOR::XS; |
|
|
370 | my $coder = CBOR::XS->new; |
|
|
371 | |
|
|
372 | $hdl->on_read (sub { |
|
|
373 | $AnyEvent::MP::Kernel::SRCNODE = $node; |
|
|
374 | |
|
|
375 | AnyEvent::MP::Kernel::_inject (@$_) |
|
|
376 | for $coder->incr_parse_multiple ($_[0]{rbuf}); |
|
|
377 | |
|
|
378 | () |
|
|
379 | }); |
363 | if ($framing eq "json") { |
380 | } elsif ($framing eq "json") { |
|
|
381 | require JSON::XS; |
364 | my $coder = JSON::XS->new->utf8; |
382 | my $coder = JSON::XS->new->utf8; |
365 | |
383 | |
366 | $hdl->on_read (sub { |
384 | $hdl->on_read (sub { |
367 | $AnyEvent::MP::Kernel::SRCNODE = $node; |
385 | $AnyEvent::MP::Kernel::SRCNODE = $node; |
368 | |
386 | |
… | |
… | |
475 | |
493 | |
476 | =head3 First Greeting Line |
494 | =head3 First Greeting Line |
477 | |
495 | |
478 | Example: |
496 | Example: |
479 | |
497 | |
480 | aemp;0;rain;tls_sha3_512,hmac_sha3_512,tls_anon,cleartext;json,storable;timeout=12;peeraddr=10.0.0.1:48082 |
498 | aemp;0;rain;tls_sha3_512,hmac_sha3_512,tls_anon,cleartext;cbor,json,storable;timeout=12;peeraddr=10.0.0.1:48082 |
481 | |
499 | |
482 | The first line contains strings separated (not ended) by C<;> |
500 | The first line contains strings separated (not ended) by C<;> |
483 | characters. The first five strings are fixed by the protocol, the |
501 | characters. The first five strings are fixed by the protocol, the |
484 | remaining strings are C<KEY=VALUE> pairs. None of them may contain C<;> |
502 | remaining strings are C<KEY=VALUE> pairs. None of them may contain C<;> |
485 | characters themselves (when escaping is needed, use C<%3b> to represent |
503 | characters themselves (when escaping is needed, use C<%3b> to represent |