mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-16 08:16:38 +02:00
Merge bitcoin/bitcoin#34401: kernel: add serialization method for btck_BlockHeader API
577a3e74c8test: Add check for return type in `HasToBytes` concept (yuvicc)1ad551281akernel: Add Block Header serialization method (yuvicc)86662623ecAdd `SpanWriter` class for zero-allocation stream writing (yuvicc) Pull request description: This adds serialization for `btck_BlockHeader` API. Also, updated the `CheckHandle` to compare the byte content instead of size. The changes here is done in two commits. First commit adds the `SpanWriter` class and next one moves the block header serialization to `SpanWriter`. See commit message for more details. Follow-up to #33822 . ACKs for top commit: stickies-v: re-ACK577a3e74c8alexanderwiederin: ACK577a3e74c8theStack: Code-review ACK577a3e74c8w0xlt: ACK577a3e74c8Tree-SHA512: 1eda5b204588ccb23e9357f68c5529474e7d248736a371c47d8db71ba6ca95e121869514478ad7a519d190e4c30725f64fd1ef4dd9f97d2627dc4441e51458e0
This commit is contained in:
@@ -208,6 +208,28 @@ BOOST_AUTO_TEST_CASE(streams_vector_writer)
|
||||
vch.clear();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(streams_span_writer)
|
||||
{
|
||||
unsigned char a(1);
|
||||
unsigned char b(2);
|
||||
unsigned char bytes[] = {3, 4, 5, 6};
|
||||
std::array<std::byte, 8> arr{};
|
||||
|
||||
// Test operator<<
|
||||
SpanWriter writer{arr};
|
||||
writer << a << b;
|
||||
BOOST_CHECK_EQUAL(HexStr(arr), "0102000000000000");
|
||||
|
||||
// Use variadic constructor and write to subspan.
|
||||
SpanWriter{std::span{arr}.subspan(2), a, bytes, b};
|
||||
BOOST_CHECK_EQUAL(HexStr(arr), "0102010304050602");
|
||||
|
||||
// Writing past the end throws
|
||||
std::array<std::byte, 1> small{};
|
||||
BOOST_CHECK_THROW(SpanWriter(std::span{small}, a, b), std::ios_base::failure);
|
||||
BOOST_CHECK_THROW(SpanWriter(std::span{small}) << a << b, std::ios_base::failure);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(streams_vector_reader)
|
||||
{
|
||||
std::vector<unsigned char> vch = {1, 255, 3, 4, 5, 6};
|
||||
|
||||
Reference in New Issue
Block a user