
Bit::MorseSignals - The MorseSignals protocol.

Version 0.06

use Bit::MorseSignals::Emitter;
use Bit::MorseSignals::Receiver;
my $deuce = new Bit::MorseSignals::Emitter;
my $pants = new Bit::MorseSignals::Receiver done => sub { print $_[1], "\n" };
$deuce->post('HLAGH') for 1 .. 3;
$pants->push while defined ($_ = $deuce->pop);

In unidirectionnal communication channels (such as networking or IPC), the main issue is often to know the length of the message. Some possible solutions are fixed-length messages (which is quite cumbersome) or a special ending sequence (but it no longer can appear in the data). This module proposes another solution, by using a begin/end signature specialized for each message.
An actual implementation is also provided :
Go to those pages if you just want the stuff done and don't care about how it gets there.

Each byte of the data string is converted into its bits sequence, with bits of lowest weight coming first. All those bits sequences are put into the same order as the characters occur in the string.
The header is composed of three bits (lowest weight coming first) :
The emitter computes then the longuest sequence of successives 0 (say, m) and 1 (n) in the concatenation of the header and the data. A signature is then chosen :
The signal is then formed by concatenating the signature, the header, the data bits and the reversed signature (i.e. the bits of the signature in the reverse order).
a ... a b | t0 t1 r | ... data ... | b a ... a
signature | header | data | reversed signature
The receiver knows that the signature has been sent when it has catched at least one 0 and one 1. The signal is completely transferred when it has received for the first time the whole reversed signature.

BM_DATA_AUTODefault for non-references messages. Try to guess if the given scalar is an UTF-8 string with Encode::is_utf8.
BM_DATA_PLAINTreats the data as a plain string. No extra mangling in done.
BM_DATA_UTF8Treats the data as an UTF-8 string. The string is Encode::encode_utf8'd in a binary string before sending, and Encode::decode_utf8'd by the receiver.
BM_DATA_STORABLEThe scalar, array or hash reference given is Storable::freeze'd by the sender and Storable::thaw'd by the receiver.

The constants "BM_DATA_AUTO", "BM_DATA_PLAIN", "BM_DATA_UTF8" and "BM_DATA_STORABLE" are only exported on request, either by specifying their names or the ':consts' tag.

Carp (standard since perl 5), Encode (since perl 5.007003), Storable (idem).

Bit::MorseSignals::Emitter, Bit::MorseSignals::Receiver.

Vincent Pit, <perl at profvince.com>, http://www.profvince.com.
You can contact me by mail or on #perl @ FreeNode (vincent or Prof_Vince).

Please report any bugs or feature requests to bug-bit-morsesignals at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bit-MorseSignals. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

You can find documentation for this module with the perldoc command.
perldoc Bit::MorseSignals
Tests code coverage report is available at http://www.profvince.com/perl/cover/Bit-MorseSignals.

Copyright 2008 Vincent Pit, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.