Skip to content

Commit

Permalink
add output operator into buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
makeyavelly committed Jan 24, 2023
1 parent 21e707a commit 2c8a03e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 16 additions & 0 deletions core/buffer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <bitset>
#include <cassert>
#include <cstddef>
#include <cstring>
Expand Down Expand Up @@ -141,5 +142,20 @@ namespace core {
std::memcpy(data_, source, bytes);
}
}

template <class stream_t>
friend stream_t& operator<<(stream_t &stream, const buffer& buf) {
if (!buf.data_) {
stream << "{NULL_BITMASK}";
return stream;
}
for (auto i = 0u; i < buf.size_; ++i) {
if (i > 0) {
stream << "'";
}
stream << std::bitset<8>(*(reinterpret_cast<const uint8_t*>(buf.data_) + i));
}
return stream;
}
};
} // namespace core
8 changes: 1 addition & 7 deletions core/uvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <cstddef>
#include <type_traits>
#include <vector>
#include <bitset>

#include "core/assert/assert.hpp"

Expand Down Expand Up @@ -133,12 +132,7 @@ namespace core {

template <class stream_t>
friend stream_t& operator<<(stream_t &stream, const uvector& v) {
for (auto i = 0u; i < v.storage_.size(); ++i) {
if (i > 0) {
stream << "'";
}
stream << std::bitset<8>(*reinterpret_cast<const uint8_t*>(v.storage_.data() + i));
}
stream << v.storage_;
return stream;
}
};
Expand Down

0 comments on commit 2c8a03e

Please sign in to comment.