ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/MP/Transport.pm
(Generate patch)

Comparing AnyEvent-MP/MP/Transport.pm (file contents):
Revision 1.86 by root, Sun Aug 28 14:38:28 2016 UTC vs.
Revision 1.87 by root, Sun Aug 28 15:38:42 2016 UTC

26 26
27use Scalar::Util (); 27use Scalar::Util ();
28use List::Util (); 28use List::Util ();
29use MIME::Base64 (); 29use MIME::Base64 ();
30 30
31use JSON::XS ();
32use Digest::SHA3 (); 31use Digest::SHA3 ();
33use Digest::HMAC (); 32use Digest::HMAC ();
34 33
35use AnyEvent (); 34use AnyEvent ();
36use AnyEvent::Socket (); 35use 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
478Example: 496Example:
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
482The first line contains strings separated (not ended) by C<;> 500The first line contains strings separated (not ended) by C<;>
483characters. The first five strings are fixed by the protocol, the 501characters. The first five strings are fixed by the protocol, the
484remaining strings are C<KEY=VALUE> pairs. None of them may contain C<;> 502remaining strings are C<KEY=VALUE> pairs. None of them may contain C<;>
485characters themselves (when escaping is needed, use C<%3b> to represent 503characters themselves (when escaping is needed, use C<%3b> to represent

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines