mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Merge bitcoin/bitcoin#23451: span: Add std::byte helpers
faa3ec2304span: Add std::byte helpers (MarcoFalke)fa18038f51refactor: Use ignore helper when unserializing an invalid pubkey (MarcoFalke)fabe18d0b3Use value_type in CDataStream where possible (MarcoFalke) Pull request description: This adds (currently unused) span std::byte helpers, so that they can be used in new code. The refactors are also required for https://github.com/bitcoin/bitcoin/pull/23438, but they are split up because the other pull doesn't compile with msvc right now. The third commit is not needed for the other pull, but still nice. ACKs for top commit: klementtan: reACKfaa3ec2. Verified that all the new `std::byte` helper functions are tested. laanwj: Code review ACKfaa3ec2304Tree-SHA512: b1f6af39f03ea4dfebf20d4a8538fa993a6104e7fc92ddf0c4606a7efc3ca9a8c1a4741d98a1418569c11bb9ce9258bf0c0c06d93d85ed7e208902a2db04e407
This commit is contained in:
@@ -151,12 +151,25 @@ BOOST_AUTO_TEST_CASE(util_HexStr)
|
||||
HexStr(Span<const unsigned char>(ParseHex_expected, ParseHex_expected)),
|
||||
"");
|
||||
|
||||
std::vector<unsigned char> ParseHex_vec(ParseHex_expected, ParseHex_expected + 5);
|
||||
{
|
||||
const std::vector<char> in_s{ParseHex_expected, ParseHex_expected + 5};
|
||||
const Span<const uint8_t> in_u{MakeUCharSpan(in_s)};
|
||||
const Span<const std::byte> in_b{MakeByteSpan(in_s)};
|
||||
const std::string out_exp{"04678afdb0"};
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
HexStr(ParseHex_vec),
|
||||
"04678afdb0"
|
||||
);
|
||||
BOOST_CHECK_EQUAL(HexStr(in_u), out_exp);
|
||||
BOOST_CHECK_EQUAL(HexStr(in_s), out_exp);
|
||||
BOOST_CHECK_EQUAL(HexStr(in_b), out_exp);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(span_write_bytes)
|
||||
{
|
||||
std::array mut_arr{uint8_t{0xaa}, uint8_t{0xbb}};
|
||||
const auto mut_bytes{MakeWritableByteSpan(mut_arr)};
|
||||
mut_bytes[1] = std::byte{0x11};
|
||||
BOOST_CHECK_EQUAL(mut_arr.at(0), 0xaa);
|
||||
BOOST_CHECK_EQUAL(mut_arr.at(1), 0x11);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_Join)
|
||||
|
||||
Reference in New Issue
Block a user