libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
hexdump.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <cstdint>
14#include <cstddef>
15#include <promeki/namespace.h>
16#include <promeki/string.h>
17#include <promeki/buffer.h>
18
19PROMEKI_NAMESPACE_BEGIN
20
46class HexDump {
47 public:
49 HexDump() = default;
50
56 HexDump &setBytesPerLine(size_t n) {
57 _bytesPerLine = n < 1 ? 1 : n;
58 return *this;
59 }
60
67 HexDump &setShowAddress(bool on) {
68 _showAddress = on;
69 return *this;
70 }
71
78 HexDump &setBaseAddress(uint64_t addr) {
79 _baseAddress = addr;
80 return *this;
81 }
82
88 HexDump &setAddressDigits(int digits) {
89 _addressDigits = digits < 1 ? 1 : digits;
90 return *this;
91 }
92
98 HexDump &setAddressSuffix(const String &suffix) {
99 _addressSuffix = suffix;
100 return *this;
101 }
102
111 HexDump &setShowAscii(bool on) {
112 _showAscii = on;
113 return *this;
114 }
115
122 HexDump &setNonPrintable(char c) {
123 _nonPrintable = c;
124 return *this;
125 }
126
133 HexDump &setUppercase(bool on) {
134 _uppercase = on;
135 return *this;
136 }
137
144 HexDump &setIndent(const String &indent) {
145 _indent = indent;
146 return *this;
147 }
148
155 String build(const void *data, size_t len) const;
156
158 String build(const Buffer &buf) const {
159 return build(buf.data(), buf.size());
160 }
161
162 private:
163 size_t _bytesPerLine = 16;
164 uint64_t _baseAddress = 0;
165 int _addressDigits = 8;
166 String _addressSuffix = ": ";
167 String _indent;
168 char _nonPrintable = '.';
169 bool _showAddress = true;
170 bool _showAscii = true;
171 bool _uppercase = true;
172};
173
174PROMEKI_NAMESPACE_END
175
176#endif // PROMEKI_ENABLE_CORE