NAME
Test::HexDifferences::HexDump - Format binary to hexadecimal strings
VERSION
0.008
SYNOPSIS
use Test::HexDifferences::HexDump;
$string = hex_dump(
$binary,
);
$string = hex_dump(
$binary,
{
address => $start_address,
format => "%a : %4C : %d\n",
}
);
Format elements
Every format element in the format string is starting with % like sprintf.
If the given format is shorter defined as needed for the data length the remaining data are displayed in default format. If the given format is longer defined as the data length the output will filled with space and it stops before next repetition.
Data format
It is not very clever to use little-endian formats for tests. There is a fallback to bytes if multibyte formats can not displayed.
%C - unsigned char
%S - unsigned 16-bit, endian depends on machine
%S< - unsigned 16-bit, little-endian
%S> - unsigned 16-bit, big-endian
%v - unsigned 16-bit, little-endian
%n - unsigned 16-bit, big-endian
%L - unsigned 32-bit, endian depends on machine
%L< - unsigned 32-bit, little-endian
%L> - unsigned 32-bit, big-endian
%V - unsigned 32-bit, little-endian
%N - unsigned 32-bit, big-endian
%Q - unsigned 64-bit, endian depends on machine
%Q< - unsigned 64-bit, little-endian
%Q> - unsigned 64-bit, big-endian
"pack" and "unpack" before Perl v5.10 do not allow "<" and ">" to mark the byte order. This is allowed here for all Perl versions.
"pack" and "unpack" on a 32 bit machine do not allow the "Q" formats. This is allowed here for all machines.
Address format
%a - 16 bit address
%4a - 16 bit address
%8a - 32 bit address
ASCII format
It can not display all chars. First it must be a printable ASCII char. It can not be anything of space, q{.}, q{'}, q{"} or q{\}. Otherwise q{.} will be printed.
%d - display ASCII
Repetition
%*x - repetition endless
%1x - repetition 1 time
%2x - repetition 2 times
...
Special formats
%\n - ignore \n
Default format
The default format is:
"%a : %4C : %d\n"
or fully written as
"%a : %4C : %d\n%*x"
Complex formats
The %...x allows to write mixed formats e.g.
Format:
%a : %N %4C : %d\n%1x%
%a : %n %2C : %d\n%*x
Input:
\0x01\0x23\0x45\0x67\0x89\0xAB\0xCD\0xEF
\0x01\0x23\0x45\0x67
\0x89\0xAB\0xCD\0xEF
Output:
0000 : 01234567 89 AB CD EF : .#-Eg...
0008 : 0123 45 67 : .#-E
000C : 89AB CD EF : g...
EXAMPLE
Inside of this Distribution is a directory named example. Run this *.t files.
DESCRIPTION
This is a formatter for binary data.
SUBROUTINES/METHODS
subroutine hex_dump
$string = hex_dump(
$binary,
{
address => $display_start_address,
format => $format_string,
}
);
DIAGNOSTICS
nothing
CONFIGURATION AND ENVIRONMENT
nothing
DEPENDENCIES
INCOMPATIBILITIES
none
BUGS AND LIMITATIONS
none
SEE ALSO
Data::Hexdumper inspired by
AUTHOR
Steffen Winkler
LICENSE AND COPYRIGHT
Copyright (c) 2012 - 2014, Steffen Winkler <steffenw at cpan.org>
. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.