diff --git a/serializer.hh b/serializer.hh index 6b56040927..562c772c08 100644 --- a/serializer.hh +++ b/serializer.hh @@ -27,6 +27,7 @@ #include #include #include +#include #include "enum_set.hh" #include "utils/managed_bytes.hh" #include "bytes_ostream.hh" diff --git a/serializer_impl.hh b/serializer_impl.hh index d6b8468408..a11b6161bc 100644 --- a/serializer_impl.hh +++ b/serializer_impl.hh @@ -540,6 +540,33 @@ void serialize_fragmented(Output& out, FragmentedBuffer&& v) { serializer::write_fragmented(out, std::forward(v)); } +template +struct serializer> { + template + static std::optional read(Input& in) { + std::optional v; + auto b = deserialize(in, boost::type()); + if (b) { + v = deserialize(in, boost::type()); + } + return v; + } + template + static void write(Output& out, const std::optional& v) { + serialize(out, bool(v)); + if (v) { + serialize(out, v.value()); + } + } + template + static void skip(Input& in) { + auto present = deserialize(in, boost::type()); + if (present) { + serializer::skip(in); + } + } +}; + template struct serializer> { template