From faaf4800aa752dde63b8987b1eb0de4e54acf717 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Wed, 18 Dec 2024 11:34:49 +0100 Subject: [PATCH] Allow std::span in stream serialization Future code can now use std::span in stream serialization, similar to the existing serialization helpers for std::array or Span. --- src/serialize.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/serialize.h b/src/serialize.h index 2af998f3c5..6384c95dba 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -264,6 +264,7 @@ 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 void Serialize(Stream& s, const B (&a)[N]) { s.write(MakeByteSpan(a)); } template void Serialize(Stream& s, const std::array& a) { s.write(MakeByteSpan(a)); } +template void Serialize(Stream& s, std::span span) { s.write(std::as_bytes(span)); } template void Serialize(Stream& s, Span span) { s.write(AsBytes(span)); } template void Unserialize(Stream&, V) = delete; // char serialization forbidden. Use uint8_t or int8_t @@ -278,6 +279,7 @@ template inline void Unserialize(Stream& s, int64_t& a ) { a = template inline void Unserialize(Stream& s, uint64_t& a) { a = ser_readdata64(s); } template void Unserialize(Stream& s, B (&a)[N]) { s.read(MakeWritableByteSpan(a)); } template void Unserialize(Stream& s, std::array& a) { s.read(MakeWritableByteSpan(a)); } +template void Unserialize(Stream& s, std::span span) { s.read(std::as_writable_bytes(span)); } 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); }