Pigweed
 
Loading...
Searching...
No Matches
pw::dump::FormattedHexDumper Class Reference

#include <hex_dump.h>

Classes

struct  Flags
 

Public Types

enum  AddressMode { kDisabled = 0 , kOffset = 1 , kAbsolute = 2 }
 

Public Member Functions

 FormattedHexDumper (span< char > dest)
 
 FormattedHexDumper (span< char > dest, Flags config_flags)
 
Status SetLineBuffer (span< char > dest)
 
Status BeginDump (ConstByteSpan data)
 
Status DumpLine ()
 

Public Attributes

Flags flags
 

Detailed Description

The formatted hex dumper is a configurable class that can dump hex in various formats. The default produced output is xxd compatible, though there are options to further adjust the output. One example is address prefixing, where base memory address of each line is used instead of an offset.

It is strongly recommended NOT to directly depend on this dump format; pw_hex_dump does NOT guarantee stability for the output format, but strives to remain xxd compatible.

Default:

Offs. 0 1 2 3 4 5 6 7 8 9 A B C D E F Text
0000: A4 CC 32 62 9B 46 38 1A 23 1A 2A 7A BC E2 40 A0 ..2b.F8.#.*z..@.
0010: FF 33 E5 2B 9E 9F 6B 3C BE 9B 89 3C 7E 4A 7A 48 .3.+..k<...<~JzH
0020: 18 .

Example 1: (32-bit machine, group_every=4, prefix_mode=kAbsolute, bytes_per_line = 8)

Address 0 4 Text
0x20000000: A4CC3262 9B46381A ..2b.F8.
0x20000008: 231A2A7A BCE240A0 #.*z..@.
0x20000010: FF33E52B 9E9F6B3C .3.+..k<
0x20000018: BE9B893C 7E4A7A48 ...<~JzH
0x20000020: 18 .

Example 2: (group_every=1, bytes_per_line = 16)

Offs. 0 1 2 3 4 5 6 7 8 9 A B C D E F
0000: A4 CC 32 62 9B 46 38 1A 23 1A 2A 7A BC E2 40 A0
0010: FF 33 E5 2B 9E 9F 6B 3C BE 9B 89 3C 7E 4A 7A 48
0020: 18

Example 3: (group_every=0, prefix_mode=kNone, show_header=false, show_ascii=false)

A4CC32629B46381A231A2A7ABCE240A0
FF33E52B9E9F6B3CBE9B893C7E4A7A48
18

Member Function Documentation

◆ BeginDump()

Status pw::dump::FormattedHexDumper::BeginDump ( ConstByteSpan  data)

Begin dumping the provided data. Does NOT populate the line buffer with a string, simply resets the statefulness to track this buffer.

Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*    OK: Ready to begin dump.
* 
*    INVALID_ARGUMENT: The source data starts at null, but has been set.
* 
*    FAILED_PRECONDITION: Line buffer too small to hold current formatting
*    settings.
* 
*  

◆ DumpLine()

Status pw::dump::FormattedHexDumper::DumpLine ( )

Dumps a single line to the line buffer.

Example usage:

std::array<char, 80> temp;
FormattedHexDumper hex_dumper(temp);
hex_dumper.BeginDump(my_data);
while(hex_dumper.DumpLine().ok()) {
LOG_INFO("%s", temp.data());
}
Definition: hex_dump.h:81
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*    OK:  A line has been written to the line buffer.
* 
*    RESOURCE_EXHAUSTED:  All the data has been dumped.
* 
*    FAILED_PRECONDITION:  Destination line buffer is too small to fit
*    current formatting configuration.
* 
*  

◆ SetLineBuffer()

Status pw::dump::FormattedHexDumper::SetLineBuffer ( span< char >  dest)

Set the destination buffer that the hex dumper will write to line-by-line.

Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
* 
*    RESOURCE_EXHAUSTED: The buffer was set, but is too small to fit the
*    current formatting configuration.
* 
*    INVALID_ARGUMENT: The destination buffer is invalid (nullptr or zero-
*    length).
* 
*  

Member Data Documentation

◆ flags

Flags pw::dump::FormattedHexDumper::flags
Initial value:
= {.bytes_per_line = 16,
.group_every = 1,
.show_ascii = true,
.show_header = true,
.prefix_mode = AddressMode::kOffset}

The documentation for this class was generated from the following file: