diff --git a/serializer_impl.hh b/serializer_impl.hh index 4750b52680..0215ec626f 100644 --- a/serializer_impl.hh +++ b/serializer_impl.hh @@ -342,26 +342,38 @@ struct serializer> { } }; -template +template class deserialized_bytes_proxy { - seastar::memory_input_stream _stream; + Stream _stream; + + template + friend class deserialized_bytes_proxy; public: - explicit deserialized_bytes_proxy(seastar::memory_input_stream stream) + explicit deserialized_bytes_proxy(Stream stream) : _stream(std::move(stream)) { } - buffer_view view() const { - GCC6_CONCEPT(static_assert(FragmentRange>)); + template>> + deserialized_bytes_proxy(deserialized_bytes_proxy proxy) + : _stream(std::move(proxy._stream)) { } + + auto view() const { + if constexpr (std::is_same_v) { + return bytes_view(reinterpret_cast(_stream.begin()), _stream.size()); + } else { + using iterator_type = typename Stream::iterator_type ; + GCC6_CONCEPT(static_assert(FragmentRange>)); return seastar::with_serialized_stream(_stream, seastar::make_visitor( - [&] (typename seastar::memory_input_stream::simple stream) { - return buffer_view(bytes_view(reinterpret_cast(stream.begin()), + [&] (typename seastar::memory_input_stream::simple stream) { + return buffer_view(bytes_view(reinterpret_cast(stream.begin()), stream.size())); }, - [&] (typename seastar::memory_input_stream::fragmented stream) { - return buffer_view(bytes_view(reinterpret_cast(stream.first_fragment_data()), + [&] (typename seastar::memory_input_stream::fragmented stream) { + return buffer_view(bytes_view(reinterpret_cast(stream.first_fragment_data()), stream.first_fragment_size()), stream.size(), stream.fragment_iterator()); } )); + } } [[gnu::always_inline]] @@ -389,9 +401,9 @@ public: template<> struct serializer { template - static deserialized_bytes_proxy read(Input& in) { + static deserialized_bytes_proxy read(Input& in) { auto sz = deserialize(in, boost::type()); - return deserialized_bytes_proxy(in.read_substream(sz)); + return deserialized_bytes_proxy(in.read_substream(sz)); } template static void write(Output& out, bytes_view v) {