Skip to content

Commit

Permalink
Add byte reader read_bytes_raw() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Aug 18, 2024
1 parent fbb888e commit 5938210
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions include/bitcoin/system/impl/stream/streamers/byte_reader.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ long_hash_cptr byte_reader<IStream>::read_long_hash_cptr() NOEXCEPT
template <typename IStream>
data_chunk byte_reader<IStream>::read_bytes() NOEXCEPT
{
// Count bytes to the end, avoids push_back reallocations.
// Count bytes to the end, avoids reallocations.
size_t size{};
while (!get_exhausted())
{
Expand All @@ -365,7 +365,7 @@ data_chunk byte_reader<IStream>::read_bytes() NOEXCEPT
template <typename IStream>
chunk_cptr byte_reader<IStream>::read_bytes_cptr() NOEXCEPT
{
// Count bytes to the end, avoids push_back reallocations.
// Count bytes to the end, avoids reallocations.
size_t size{};
while (!get_exhausted())
{
Expand All @@ -377,6 +377,21 @@ chunk_cptr byte_reader<IStream>::read_bytes_cptr() NOEXCEPT
return read_bytes_cptr(size);
}

template <typename IStream>
data_chunk* byte_reader<IStream>::read_bytes_raw() NOEXCEPT
{
// Count bytes to the end, avoids reallocations.
size_t size{};
while (!get_exhausted())
{
++size;
skip_byte();
};

rewind_bytes(size);
return read_bytes_raw(size);
}

template <typename IStream>
data_chunk byte_reader<IStream>::read_bytes(size_t size) NOEXCEPT
{
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/system/stream/streamers/byte_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class byte_reader
/// Read all remaining bytes to chunk.
data_chunk read_bytes() NOEXCEPT override;
chunk_cptr read_bytes_cptr() NOEXCEPT override;
NODISCARD data_chunk* read_bytes_raw() NOEXCEPT override;

/// Read size bytes to data_chunk, return size is guaranteed.
data_chunk read_bytes(size_t size) NOEXCEPT override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class bytereader
/// Read all remaining bytes to chunk.
virtual data_chunk read_bytes() NOEXCEPT = 0;
virtual chunk_cptr read_bytes_cptr() NOEXCEPT = 0;
virtual data_chunk* read_bytes_raw() NOEXCEPT = 0;

/// Read size bytes to data_chunk, return size is guaranteed.
virtual data_chunk read_bytes(size_t size) NOEXCEPT = 0;
Expand Down

0 comments on commit 5938210

Please sign in to comment.