Acme-RFC4824
view release on metacpan or search on metacpan
--- #YAML:1.0
name: Acme-RFC4824
version: 0.02
abstract: Internet Protocol over Semaphore Flag Signaling System (SFSS)
license: perl
generated_by: ExtUtils::MakeMaker version 6.31
distribution_type: module
requires:
Moose: 0.18
Test::More: 0
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.2.html
version: 1.2
author:
Acme-RFC4824
Acme::RFC4824 is a module that tries to help you with the implementation
of RFC 4824 - IP over Semaphore Flag Signaling System.
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
make
make test
make install
lib/Acme/RFC4824.pm view on Meta::CPAN
use warnings;
use strict;
use Moose;
use Carp;
use bytes;
our $VERSION = '0.02';
# a hash ref of mappings from ASCII to ASCII art representations
has 'ascii2art_map' => (
is => 'ro',
);
# the default SFS frame size in bytes
has 'default_framesize' => (
is => 'ro',
isa => 'Int',
default => 255,
);
sub BUILD {
my $self = shift;
my $arg_ref = shift;
if (exists $arg_ref->{'DEFAULT_FRAMESIZE'}) {
if ($arg_ref->{'DEFAULT_FRAMESIZE'} > 255) {
croak "Frame size too large, can at most be 255";
}
$self->{'default_framesize'} = $arg_ref->{'DEFAULT_FRAMESIZE'};
}
# initialize mapping from characters to ASCII art
# ASCII-Art comes directly from RFC4824
$self->{'ascii2art_map'}->{'A'} = << 'XEOF';
0
/||
/ \
XEOF
$self->{'ascii2art_map'}->{'B'} = << 'XEOF';
__0
||
/ \
XEOF
$self->{'ascii2art_map'}->{'C'} = << 'XEOF';
\0
||
/ \
XEOF
$self->{'ascii2art_map'}->{'D'} = << 'XEOF';
|0
||
/ \
XEOF
$self->{'ascii2art_map'}->{'E'} = << 'XEOF';
0/
||
/ \
XEOF
$self->{'ascii2art_map'}->{'F'} = << 'XEOF';
0__
||
/ \
XEOF
$self->{'ascii2art_map'}->{'G'} = << 'XEOF';
0
||\
/ \
XEOF
$self->{'ascii2art_map'}->{'H'} = << 'XEOF';
__0
/|
/ \
XEOF
$self->{'ascii2art_map'}->{'I'} = << 'XEOF';
\0
/|
/ \
XEOF
$self->{'ascii2art_map'}->{'J'} = << 'XEOF';
|0__
|
/ \
XEOF
$self->{'ascii2art_map'}->{'K'} = << 'XEOF';
0|
/|
/ \
XEOF
$self->{'ascii2art_map'}->{'L'} = << 'XEOF';
0/
/|
/ \
XEOF
$self->{'ascii2art_map'}->{'M'} = << 'XEOF';
0__
/|
/ \
XEOF
$self->{'ascii2art_map'}->{'N'} = << 'XEOF';
0
/|\
/ \
XEOF
$self->{'ascii2art_map'}->{'O'} = << 'XEOF';
_\0
|
/ \
XEOF
$self->{'ascii2art_map'}->{'P'} = << 'XEOF';
__0|
|
/ \
XEOF
$self->{'ascii2art_map'}->{'Q'} = << 'XEOF';
__0/
|
/ \
XEOF
$self->{'ascii2art_map'}->{'R'} = << 'XEOF';
__0__
|
/ \
XEOF
$self->{'ascii2art_map'}->{'S'} = << 'XEOF';
__0
|\
/ \
XEOF
$self->{'ascii2art_map'}->{'T'} = << 'XEOF';
\0|
|
/ \
XEOF
$self->{'ascii2art_map'}->{'U'} = << 'XEOF';
\0/
|
/ \
XEOF
$self->{'ascii2art_map'}->{'V'} = << 'XEOF';
|0
|\
/ \
XEOF
$self->{'ascii2art_map'}->{'W'} = << 'XEOF';
0/_
|
/ \
XEOF
$self->{'ascii2art_map'}->{'X'} = << 'XEOF';
0/
|\
/ \
XEOF
$self->{'ascii2art_map'}->{'Y'} = << 'XEOF';
\0__
|
/ \
XEOF
$self->{'ascii2art_map'}->{'Z'} = << 'XEOF';
0__
|\
/ \
XEOF
return 1;
}
sub decode {
my $self = shift;
my $arg_ref = shift;
lib/Acme/RFC4824.pm view on Meta::CPAN
$sfs_frame .= 'AAAA'; # No checksum, so we just set it zeros
$sfs_frame .= 'R'; # Frame End, FEN
if ($type eq 'ASCII') {
return $sfs_frame;
}
else { # ASCII-ART
my @sfss_ascii_art_frames = ();
for (my $i = 0; $i < length($sfs_frame); $i++) {
my $char = substr($sfs_frame, $i, 1);
my $aa_repr = $self->ascii2art_map->{$char};
if (! defined $aa_repr) {
die "No ASCII-Art representation for '$char'";
}
push @sfss_ascii_art_frames, $aa_repr;
}
if (wantarray) {
return @sfss_ascii_art_frames;
}
else {
return join "\n", @sfss_ascii_art_frames;
}
}
}
1;
__END__
=head1 NAME
Acme::RFC4824 - Internet Protocol over Semaphore Flag Signaling System (SFSS)
=head1 VERSION
Version 0.01
=head1 SYNOPSIS
This module is used to help you implement RFC 4824 - The Transmission
of IP Datagrams over the Semaphore Flag Signaling System (SFSS).
It can be used to convert IP datagrams to SFS frames and the other
way round. Furthemore, it can be used to display an ASCII art representation
of the SFS frame.
use Acme::RFC4824;
my $sfss = Acme::RFC4824->new();
# get IP datagram from somewhere (for example Net::Pcap)
lib/Acme/RFC4824.pm view on Meta::CPAN
=over 4
=item * FRAME
An ASCII representation of the SFS frame which you would like to decode
into an IP datagram.
=back
=head2 ascii2art_map
Read-only accessor for the attribute with the same name.
Returns a hash reference that maps SFS ASCII characters to an ASCII art
representation of the given character. There is probably no need to use
this from the outside.
=head2 default_framesize
Read-only accessor for the attribute with the same name.
Returns the default SFS framesize. There is probably no need to use this
from the outside.
=head2 meta
t/01-encode_decode.t view on Meta::CPAN
TYPE => 'ASCII art',
});
if ($ENV{DEBUG}) {
diag "ASCII art array:\n" . Dumper \@ascii_art;
}
# test that the number of characters in the ASCII string is the same as
# the number of ASCII art entries
is(scalar @ascii_art, length($ascii), 'ASCII art array has same number of elements as the string is long');
# test that the last entry is the representation of 'R' (FEN)
is($sfss->ascii2art_map()->{'R'}, $ascii_art[scalar @ascii_art - 1], 'Last symbol is R (FEN)');
# test packet from RFC 4824 authors
my $test_packet2 = pack('H*', '1e1f202122232425262728292a2b2c2d2e2f3031323334353637');
my $ascii2 = 'QABAABOBPCACBCCCDCECFCGCHCICJCKCLCMCNCOCPDADBDCDDDEDFDGDHLPOMR';
my $test = $sfss->decode({
FRAME => $ascii2,
});
ok($test_packet2 eq $test, 'Test packet from RFC4824 authors decoding');
my $packet = $sfss->decode({
( run in 0.737 second using v1.01-cache-2.11-cpan-49f99fa48dc )