Files
ternfs-XTXMarkets/cpp/Bincode.cpp
Francesco Mazzoli fc0cee0e07 C++ shard
Most operations apart from spans-related ones work. Using this as
a checkpoint -- the Python code is currently not really working,
I'm working to migrate to pretty much a full C++/go world.
2022-12-10 10:55:25 +00:00

25 lines
640 B
C++

#include "Bincode.hpp"
std::ostream& operator<<(std::ostream& out, const BincodeBytes& x) {
out << "b\"";
for (int i = 0; i < x.length; i++) {
uint8_t ch = x.data[i];
if (isprint(ch)) {
out << ch;
} else if (ch == 0) {
out << "\\0";
} else {
const char cfill = out.fill();
out << std::hex << std::setfill('0');
out << "\\x" << std::setw(2) << ((int)ch);
out << std::setfill(cfill) << std::dec;
}
}
out << "\"";
return out;
}
const char* BincodeException::what() const noexcept {
return _msg.c_str();
}