mirror of
https://github.com/Zygo/bees.git
synced 2025-06-16 17:46:16 +02:00
bytevector: add ostream output with hexdump
There is a hexdump template in fs. Move hexdump to its own header, then ByteVector can use it too. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
25
lib/fs.cc
25
lib/fs.cc
@ -2,6 +2,7 @@
|
||||
|
||||
#include "crucible/error.h"
|
||||
#include "crucible/fd.h"
|
||||
#include "crucible/hexdump.h"
|
||||
#include "crucible/limits.h"
|
||||
#include "crucible/ntoa.h"
|
||||
#include "crucible/string.h"
|
||||
@ -866,30 +867,6 @@ namespace crucible {
|
||||
}
|
||||
}
|
||||
|
||||
template <class V>
|
||||
ostream &
|
||||
hexdump(ostream &os, const V &v)
|
||||
{
|
||||
os << "V { size = " << v.size() << ", data:\n";
|
||||
for (size_t i = 0; i < v.size(); i += 8) {
|
||||
string hex, ascii;
|
||||
for (size_t j = i; j < i + 8; ++j) {
|
||||
if (j < v.size()) {
|
||||
uint8_t c = v[j];
|
||||
char buf[8];
|
||||
sprintf(buf, "%02x ", c);
|
||||
hex += buf;
|
||||
ascii += (c < 32 || c > 126) ? '.' : c;
|
||||
} else {
|
||||
hex += " ";
|
||||
ascii += ' ';
|
||||
}
|
||||
}
|
||||
os << astringprintf("\t%08x %s %s\n", i, hex.c_str(), ascii.c_str());
|
||||
}
|
||||
return os << "}";
|
||||
}
|
||||
|
||||
string
|
||||
btrfs_search_type_ntoa(unsigned type)
|
||||
{
|
||||
|
Reference in New Issue
Block a user