#include "BinaryBuffer.h" #include BinaryBuffer::BinaryBuffer() {} BinaryBuffer::BinaryBuffer(std::size_t n, const byte *buf) { for (std::size_t i = 0; i < n; ++i) data.push_back(buf[i]); } BinaryBuffer& BinaryBuffer::operator<<(const std::string_view& x) { std::uint32_t len = x.size(); *this << len; for (char c : x) *this << c; return *this; } BinaryBuffer& BinaryBuffer::operator>>(std::string& x) { std::uint32_t len; *this >> len; x.resize(len); for (char& c : x) *this >> c; return *this; } std::size_t BinaryBuffer::size() const { return data.size(); } bool BinaryBuffer::empty() const { return data.empty(); } std::ostream& operator<<(std::ostream &out, const BinaryBuffer &x) { for (auto v : x.data) out.put(v); return out; } void BinaryBuffer::writeTo(std::FILE *out) const { auto sz = size(); for (std::size_t i = 0; i < sz; ++i) fputc(data[i], out); }