Provide platform-independent stream utilities.
More...
Namespaces |
namespace | bdlb |
Detailed Description
- Outline
-
-
- Purpose:
- Provide platform-independent stream utilities.
-
- Classes:
-
-
- Description:
- This component provides a namespace,
bdlb::Print
, containing utility functions for formatting data to bsl::ostream
objects. These functions provide several variations of hexadecimal format, allow platform-independent representation of void *
pointers, and can help with the indentation of hierarchical data.
- This component also provides two helper classes,
bdlb::PrintStringHexDumper
and bdlb::PrintStringSingleLineHexDumper
, that define operator<<
so they can be used in chains of <<
operations. The bdlb::PrintStringHexDumper
class produces formatted, possibly multi-line output, whereas the bdlb::PrintStringSingleLineHexDumper
class produces a simple sequence of hexadecimal digits (and no newline).
-
- xxd-Compatible hexDump:
- The output generated by the
hexDump
functions is not xxd
-compatible (see http://gd.tuwien.ac.at/linuxcommand.org/man_pages/xxd1.html
). The following perl script is provided that will convert hexDump
output into xxd
-compatible form. Run the script with a file containing the hexDump
output as the first argument. #!/usr/bin/perl -w
use strict;
my $num = 0;
while (<>) {
next if (!$_);
my $str = $_;
next if !($str =~ s/^[^:]*?:\s*
my $h = sprintf("%08X",$num);
$str =~ s/(\S{4})([\S\W]{4})\s?([\S\W]{4})([\S\W]{4})\s?([\S\W]{4})?
([\S\W]{4})?\s?([\S\W]{4})?([\S\W]{4})?/$1 $2 $3 $4 $5 $6 $7 $8/;
$str =~ s/\s \|([^|]+)\|.*$/ $1/;
print "$h: ";
print $str;
$num = $num + 16;
}
-
- Usage:
- In this section we show intended usage of this component.
-
- Example 1: Using printPtr:
- The default output produced from pointer values is non-standard across vendor platforms. The
printPtr
method addresses this inconsistency by always producing a consistent format for a given pointer size:
-
- Example 2: Using the Helper Classes:
- The two helper classes allow users to stream a hexadecimal representation of a sequence of bytes into an output stream.
- The
bdlb::PrintStringHexDumper
provides a formatted, possibly multi-line representation: The bdlb::PrintStringSingleLineHexDumper
provides a simple, single-line representation. assert("6162636465666768696A6B6C6D6E6F707172737475767778797A00"
== out2b.str());