diff --git a/include/bitcoin/system/impl/stream/streamers/byte_reader.ipp b/include/bitcoin/system/impl/stream/streamers/byte_reader.ipp index 4b72b17578..3988c29b5d 100644 --- a/include/bitcoin/system/impl/stream/streamers/byte_reader.ipp +++ b/include/bitcoin/system/impl/stream/streamers/byte_reader.ipp @@ -350,7 +350,7 @@ long_hash_cptr byte_reader::read_long_hash_cptr() NOEXCEPT template data_chunk byte_reader::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()) { @@ -365,7 +365,7 @@ data_chunk byte_reader::read_bytes() NOEXCEPT template chunk_cptr byte_reader::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()) { @@ -377,6 +377,21 @@ chunk_cptr byte_reader::read_bytes_cptr() NOEXCEPT return read_bytes_cptr(size); } +template +data_chunk* byte_reader::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 data_chunk byte_reader::read_bytes(size_t size) NOEXCEPT { diff --git a/include/bitcoin/system/stream/streamers/byte_reader.hpp b/include/bitcoin/system/stream/streamers/byte_reader.hpp index 649971d327..28c40436dc 100644 --- a/include/bitcoin/system/stream/streamers/byte_reader.hpp +++ b/include/bitcoin/system/stream/streamers/byte_reader.hpp @@ -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; diff --git a/include/bitcoin/system/stream/streamers/interfaces/bytereader.hpp b/include/bitcoin/system/stream/streamers/interfaces/bytereader.hpp index 5d18904df3..e53f0de50e 100644 --- a/include/bitcoin/system/stream/streamers/interfaces/bytereader.hpp +++ b/include/bitcoin/system/stream/streamers/interfaces/bytereader.hpp @@ -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;