From fa898e6836a8fc2c7b6c8c15ad21818b16a89863 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Mon, 11 Dec 2023 22:33:56 +0100 Subject: refactor: Print verbose serialize compiler error messages --- src/serialize.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/serialize.h') diff --git a/src/serialize.h b/src/serialize.h index 263b781f21..bbe6f54682 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -273,8 +273,8 @@ template inline void Serialize(Stream& s, int64_t a ) { ser_wri template inline void Serialize(Stream& s, uint64_t a) { ser_writedata64(s, a); } template inline void Serialize(Stream& s, const char (&a)[N]) { s.write(MakeByteSpan(a)); } template inline void Serialize(Stream& s, const unsigned char (&a)[N]) { s.write(MakeByteSpan(a)); } -template void Serialize(Stream& s, const std::array& a) { (void)/* force byte-type */UCharCast(a.data()); s.write(MakeByteSpan(a)); } -template void Serialize(Stream& s, Span span) { (void)/* force byte-type */UCharCast(span.data()); s.write(AsBytes(span)); } +template void Serialize(Stream& s, const std::array& a) { s.write(MakeByteSpan(a)); } +template void Serialize(Stream& s, Span span) { s.write(AsBytes(span)); } #ifndef CHAR_EQUALS_INT8 template void Unserialize(Stream&, char) = delete; // char serialization forbidden. Use uint8_t or int8_t @@ -290,8 +290,8 @@ template inline void Unserialize(Stream& s, int64_t& a ) { a = template inline void Unserialize(Stream& s, uint64_t& a) { a = ser_readdata64(s); } template inline void Unserialize(Stream& s, char (&a)[N]) { s.read(MakeWritableByteSpan(a)); } template inline void Unserialize(Stream& s, unsigned char (&a)[N]) { s.read(MakeWritableByteSpan(a)); } -template void Unserialize(Stream& s, std::array& a) { (void)/* force byte-type */UCharCast(a.data()); s.read(MakeWritableByteSpan(a)); } -template void Unserialize(Stream& s, Span span) { (void)/* force byte-type */UCharCast(span.data()); s.read(AsWritableBytes(span)); } +template void Unserialize(Stream& s, std::array& a) { s.read(MakeWritableByteSpan(a)); } +template void Unserialize(Stream& s, Span span) { s.read(AsWritableBytes(span)); } template inline void Serialize(Stream& s, bool a) { uint8_t f = a; ser_writedata8(s, f); } template inline void Unserialize(Stream& s, bool& a) { uint8_t f = ser_readdata8(s); a = f; } @@ -755,18 +755,23 @@ template void Serialize(Stream& os, const std::uniq template void Unserialize(Stream& os, std::unique_ptr& p); - /** * If none of the specialized versions above matched, default to calling member function. */ -template -inline void Serialize(Stream& os, const T& a) +template +concept Serializable = requires(T a, Stream s) { a.Serialize(s); }; +template + requires Serializable +void Serialize(Stream& os, const T& a) { a.Serialize(os); } -template -inline void Unserialize(Stream& is, T&& a) +template +concept Unserializable = requires(T a, Stream s) { a.Unserialize(s); }; +template + requires Unserializable +void Unserialize(Stream& is, T&& a) { a.Unserialize(is); } -- cgit v1.2.3