The AsBytes
helpers (or std::as_bytes
helpers) are architecture
dependent. For example, the below test case diff [0], applied before
this commit will pass on x86_64, but fail on s390x [1].
Fix this by replacing AsBytes
with a new ByteSpanCast
in the MakeByteSpan
helper.
This will turn the test case diff into a compile failure instead of a runtime error.
[0] test case diff:
0diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp
1index 09f77d2b61..4e56ffa351 100644
2--- a/src/test/serialize_tests.cpp
3+++ b/src/test/serialize_tests.cpp
4@@ -241,6 +241,15 @@ BOOST_AUTO_TEST_CASE(class_methods)
5 ss2 << intval << boolval << stringval << charstrval << txval;
6 ss2 >> methodtest3;
7 BOOST_CHECK(methodtest3 == methodtest4);
8+
9+ {
10+ DataStream out;
11+ std::vector<uint8_t> in_8{0x00, 0x11, 0x22, 0x33};
12+ std::vector<uint16_t> in_16{0xaabb, 0xccdd};
13+ out.write(MakeByteSpan(in_8));
14+ out.write(MakeByteSpan(in_16));
15+ BOOST_CHECK_EQUAL(HexStr(out), "00112233bbaaddcc");
16+ }
17 }
18
19 BOOST_AUTO_TEST_SUITE_END()
[1] test case failure on s390x:
test/serialize_tests.cpp(251): error: in "serialize_tests/class_methods": check HexStr(out) == "00112233bbaaddcc" has failed [00112233aabbccdd != 00112233bbaaddcc]