diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-05-10 08:22:05 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-05-10 08:22:18 +0200 |
commit | 3028a1e3848e61ad4361450d3c86417c5ef0423c (patch) | |
tree | 89eac3470dab74403420824b4e8979f05343fd3f /src | |
parent | 86e04741dd7faa525b38b5fab59cc0e7fc654972 (diff) | |
parent | fa2204f6adef493079d1ca5148b0fdc2b55816e6 (diff) | |
download | bitcoin-3028a1e3848e61ad4361450d3c86417c5ef0423c.tar.xz |
Merge bitcoin/bitcoin#21581: streams: Accept URef obj for VectorReader unserialize
fa2204f6adef493079d1ca5148b0fdc2b55816e6 streams: Accept URef obj for VectorReader unserialize (MarcoFalke)
Pull request description:
Missed in commit 172f5fa738d419efda99542e2ad2a0f4db5be580. An URef may collapse into an LRef or RRef depending on context. There is no reason to forbid RRef in `VectorReader::operator>>`, so add it for consistency.
ACKs for top commit:
ryanofsky:
Code review ACK fa2204f6adef493079d1ca5148b0fdc2b55816e6, just expanded test since last review
Tree-SHA512: 09ff4e8a918e15b08cebd8c125d37e78bfb3a635c38546fc8454a97a882b2c81c55ef552243617e78744799d31127e6fbf78c4e319c030480b370aab6f38b645
Diffstat (limited to 'src')
-rw-r--r-- | src/streams.h | 2 | ||||
-rw-r--r-- | src/test/streams_tests.cpp | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/streams.h b/src/streams.h index e78da31cbc..31407287ae 100644 --- a/src/streams.h +++ b/src/streams.h @@ -167,7 +167,7 @@ public: } template<typename T> - VectorReader& operator>>(T& obj) + VectorReader& operator>>(T&& obj) { // Unserialize from this stream ::Unserialize(*this, obj); diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp index 3079c9ff29..7af2b79f37 100644 --- a/src/test/streams_tests.cpp +++ b/src/test/streams_tests.cpp @@ -112,6 +112,17 @@ BOOST_AUTO_TEST_CASE(streams_vector_reader) BOOST_CHECK_THROW(new_reader >> d, std::ios_base::failure); } +BOOST_AUTO_TEST_CASE(streams_vector_reader_rvalue) +{ + std::vector<uint8_t> data{0x82, 0xa7, 0x31}; + VectorReader reader(SER_NETWORK, INIT_PROTO_VERSION, data, /* pos= */ 0); + uint32_t varint = 0; + // Deserialize into r-value + reader >> VARINT(varint); + BOOST_CHECK_EQUAL(varint, 54321); + BOOST_CHECK(reader.empty()); +} + BOOST_AUTO_TEST_CASE(bitstream_reader_writer) { CDataStream data(SER_NETWORK, INIT_PROTO_VERSION); |