Archive-TarGzip
view release on metacpan or search on metacpan
t/Archive/Data/Secs2.pm view on Meta::CPAN
#
if ( $reftype eq 'HASH') {
foreach (sort keys %$var ) {
push @array, ($_, $var->{$_});
}
}
elsif($reftype eq 'ARRAY') {
push @array, @$var;
}
elsif($reftype eq 'SCALAR') {
push @array, $$var;
}
elsif($reftype eq 'REF') {
push @array, $var;
}
elsif($reftype eq 'CODE') {
push @array, $var;
}
elsif($reftype eq 'GLOB') {
push @array,(*$var{SCALAR},*$var{ARRAY},*$var{HASH},*$var{CODE},
*$var{IO},*$var{NAME},*$var{PACKAGE},"*$var"),
}
else {
$event = "Unknown underlying data type\n";
@array = '';
goto EVENT;
}
return \@array;
EVENT:
$event .= "\tData::Secs2::arrayify $VERSION\n";
if($options->{warnings} ) {
warn($event);
}
elsif($options->{die}) {
die($event);
}
$event;
}
######
# Program module wide configuration
#
sub config
{
$default_options = Data::Secs2->new() unless $default_options;
my $self = UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : $default_options;
$self = ref($self) ? $self : $default_options;
$self->Data::Startup::config(@_);
}
#######
#
#
my %format = (
L => 0x00, # List (length in elements)
B => 0x20, # Binary
T => 0x24, # Boolean
A => 0x40, # ASCII
J => 0x44, # JIS-8
S8 => 0x60, # 8-byte integer (unsigned)
S1 => 0x62, # 1-byte integer (unsigned)
S2 => 0x64, # 2-byte integer (unsigned)
S4 => 0x70, # 4-byte integer (unsigned)
F8 => 0x80, # 8-byte floating
F4 => 0x90, # 4-byte floating
U8 => 0xA0, # 8-byte integer (unsigned)
U1 => 0xA4, # 1-byte integer (unsigned)
U2 => 0xA8, # 2-byte integer (unsigned)
U4 => 0xB0, # 4-byte integer (unsigned)
);
################
# This subroutine walks a nested data structure, and listify each level
# into a perlified SECII message. The assumption is that the nested
# data structure consists of only references to Perl arrays,
#
sub listify
{
######
# This subroutine uses no object data; therefore,
# drop any class or object.
#
$default_options = Data::Secs2->new() unless $default_options;
my $self = UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : $default_options;
$self = ref($self) ? $self : $default_options;
my %options = %$self; # try not to mangle or bless the default options
#########
# Return an array, so going to walk the array, looking
# for hash and array references to arrayify
#
# Use a stack for the walk instead of recursing. Easier
# to maintain when the data is on a separate stack instead
# of the call (return) stack and only the pertient data
# is stored on the separate stack. The return stack does
# not grow. Instead the separate recurse stack grows.
#
my %dups = ();
my @vars = ();
my @index = ();
#####
# Perl format code
my @secs_obj = ('U1',[80]);
my $i = 0;
my @var = @_; # do not clobber @_ so make a copy
my $var = \@var;
my ($is_numeric,$format,$num,$ref,$ref_dup,@dup_index,$str);
for(;;) {
while($i < @$var) {
t/Archive/Data/Secs2.pm view on Meta::CPAN
=over
=item 1
an item header(IH) with a format code,
and the number of bytes in the following body
=item 2
followed by the item body (IB) consisting of a number of elements.
=back
A item (IB) may consist of zero bytes in which there are no body
bytes for that item. As established by SEMI E5-94, 6.2.2,
=over 4
=item
consists of groups of data of the same representation
in order to save repeated item headers
=item integers
Most Significant Byte (MS) sent first
=item signed integers
signed integers are two's complement, MSB sent first
=item floating point numbers
IEEE 754, sign bit sent first
=item non-printing ASCII
equipment specific
=back
As specified in E4-95 6.3, a list element consists of an
ordered set of elements that are either an item element or a list element.
Because a list element may contains a list element, and SEMI E5 places
no restriction on the level of nesting, SECSII lists may
be nested to theoretically to any level.
Practically nested is limited by machine resources.
A list has the same header format as an item, no body and the length
number is the number of elements in the list instead of the number of
bytes in the body.
The item and list header format codes are as in below Table 1
Table 1 Item Format Codes
unpacked binary octal hex description
----------------------------------------
L 000000 00 0x00 LIST (length of elements, not bytes)
B 001000 10 0x20 Binary
T 001001 11 0x24 Boolean
A 010000 20 0x40 ASCII
J 010001 21 0x44 JIS-8
S8 011000 30 0x60 8-byte integer (signed)
S1 011001 31 0x62 1-byte integer (signed)
S2 011010 32 0x64 2-byte integer (signed)
S4 011100 34 0x70 4-byte integer (signed)
F8 100000 40 0x80 8-byte floating
F4 100100 44 0x90 4-byte floating
U8 101000 50 0xA0 8-byte integer (unsigned)
U1 101001 51 0xA4 1-byte integer (unsigned)
U2 101010 52 0xA8 2-byte integer (unsigned)
U4 101100 54 0xB0 4-byte integer (unsigned)
Table 1 complies to SEMI E5-94 Table 1, p.94, with an unpack text
symbol and hex columns added. The hex column is the upper
Most Significant Bits (MSB) 6 bits
of the format code in the SEMI E5-94 item header (IH) or list header (LH)
with the the lower Least Significant BIt (LSB) set to zero.
Figure 1 below provides the layout for a SEMI E5-94 header
and complies to SEMI E5-94 Figure 2, p. 92, except Figure 1
renumbers the bits from 0 to 7 instead of from 1 to 8.
bits
MSB LSB
7 6 5 4 3 2 1 0
+-------+-------+-------+-------+-------+-------+-------+-------+
| Format code |# length bytes |
+---------------------------------------------------------------+
|MSB MS length byte LSB |
+---------------------------------------------------------------+
| length byte |
+---------------------------------------------------------------+
| LS length byte |
+---------------------------------------------------------------+
Figure 1 Item and List Header
=head2 SECS Object
This section establishes a formal definition of a SECS Object
and introduces technical definitions that supercede Webster
Dictionary definitions and only apply for the content of
this Program Module for the following:
SECS Object (SECS-OBJ), Element, Item Element (IE),
List Element (LE), Element Header (EH), Element Format Code (EFC),
Element Body (EB) and Element Cells (EC).
If any of the technical definitions appear to have sexual innuendos,
it is entirely coincidental.
The definitions should be interpereted only on their technical merits.
Any other interperetation is totally unprofessional.
A SECS Object is a Perl C<ARRAY> that mimics the
SEMI E5-94 SECS-II, section 6, data structure where
SECS-II transmitted bytes are layed out in memory.
The relation between between SEMI E5-94 "byte sent first" is that
"bytes sent first" will have the lowest byte address.
A SECS Object consists of consecutive ordered Elements stored
( run in 3.157 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )