Tom Molesworth > Protocol-ControlChannel-0.003 > Protocol::ControlChannel

Download:
Protocol-ControlChannel-0.003.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.003   Source  

NAME ^

Protocol::ControlChannel - simple binary protocol for exchanging key/value pairs

VERSION ^

version 0.003

SYNOPSIS ^

 my $cc = Protocol::ControlChannel->new;
 my $data = $cc->create_frame(key => 'value');
 my $frame = $cc->extract_frame(\$data);
 print 'Key: ' . $frame->{key} . ', value ' . $frame->{value} . "\n";

DESCRIPTION ^

This is the abstract implementation for a wire protocol which can be used to exchange data between two endpoints, as a series of key/value pairs.

Typical use-case is for passing events between remote processes/hosts.

The data packet looks like this:

Types are currently 0 for 'plain text', 1 for 'Storable::nfreeze'. It's quite possible that Sereal support will be added soon.

Usage is simple: instantiate, call methods, if anything returns undef then things have gone wrong so you're advised to terminate that session. If you're exchanging packets via UDP then this may not be so simple.

Note that content is either Perl data structures (i.e. a reference), or byte data. If you have a string, you'll need to pick a suitable encoding and decoding - probably UTF-8.

METHODS ^

new

Instantiate an object. Not technically necessary, since all the other methods could just as well be class methods for the moment, but in future this is likely to change.

extract_frame

Given a scalar ref to a byte buffer, will attempt to extract the next frame.

If a full, valid frame was found, it will be decoded, removed from the buffer, and returned as a hashref.

If not, you get undef.

If something went wrong, you'll probably get undef at the moment. In future this may raise an exception.

create_frame

Creates a frame. Takes a key => value pair, and returns them in packet form.

Key must be something that can be utf8-encoded - so 'a perl string', or an object that stringifies sanely.

SEE ALSO ^

Any of the other protocols that look very similar to this one...

AUTHOR ^

Tom Molesworth <cpan@entitymodel.com>

LICENSE ^

Copyright Tom Molesworth 2012-2013. Licensed under the same terms as Perl itself.

syntax highlighting: