mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Allow std::byte serialization
This commit is contained in:
parent
fade43edc4
commit
fac6af16f4
2 changed files with 6 additions and 2 deletions
|
@ -192,6 +192,7 @@ template<typename X> const X& ReadWriteAsHelper(const X& x) { return x; }
|
|||
#ifndef CHAR_EQUALS_INT8
|
||||
template <typename Stream> void Serialize(Stream&, char) = delete; // char serialization forbidden. Use uint8_t or int8_t
|
||||
#endif
|
||||
template <typename Stream> void Serialize(Stream& s, std::byte a) { ser_writedata8(s, uint8_t(a)); }
|
||||
template<typename Stream> inline void Serialize(Stream& s, int8_t a ) { ser_writedata8(s, a); }
|
||||
template<typename Stream> inline void Serialize(Stream& s, uint8_t a ) { ser_writedata8(s, a); }
|
||||
template<typename Stream> inline void Serialize(Stream& s, int16_t a ) { ser_writedata16(s, a); }
|
||||
|
@ -207,6 +208,7 @@ template <typename Stream, typename B> void Serialize(Stream& s, Span<B> span) {
|
|||
#ifndef CHAR_EQUALS_INT8
|
||||
template <typename Stream> void Unserialize(Stream&, char) = delete; // char serialization forbidden. Use uint8_t or int8_t
|
||||
#endif
|
||||
template <typename Stream> void Unserialize(Stream& s, std::byte& a) { a = std::byte{ser_readdata8(s)}; }
|
||||
template<typename Stream> inline void Unserialize(Stream& s, int8_t& a ) { a = ser_readdata8(s); }
|
||||
template<typename Stream> inline void Unserialize(Stream& s, uint8_t& a ) { a = ser_readdata8(s); }
|
||||
template<typename Stream> inline void Unserialize(Stream& s, int16_t& a ) { a = ser_readdata16(s); }
|
||||
|
|
|
@ -244,11 +244,13 @@ BOOST_AUTO_TEST_CASE(class_methods)
|
|||
{
|
||||
DataStream ds;
|
||||
const std::string in{"ab"};
|
||||
ds << Span{in};
|
||||
ds << Span{in} << std::byte{'c'};
|
||||
std::array<std::byte, 2> out;
|
||||
ds >> Span{out};
|
||||
std::byte out_3;
|
||||
ds >> Span{out} >> out_3;
|
||||
BOOST_CHECK_EQUAL(out.at(0), std::byte{'a'});
|
||||
BOOST_CHECK_EQUAL(out.at(1), std::byte{'b'});
|
||||
BOOST_CHECK_EQUAL(out_3, std::byte{'c'});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue