NAME
Test::HexDifferences::HexDump - Format binary to hexadecimal strings
VERSION
0.002
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.
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
%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
%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
%Q< - unsigned 64-bit, little-endian
%Q> - unsigned 64-bit, big-endian
Address format
%a - 16 bit address
%4a - 16 bit address
%8a - 32 bit address
ascii format
It can not display all chars. Fist 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, 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.