From 4ca991ea65f18e4a3380958c8c19e12fbda50019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dziepak?= Date: Fri, 24 Aug 2018 14:05:58 +0100 Subject: [PATCH] idl: deserialized_bytes_proxy do not assume presence of iterator_type deserialized_bytes_proxy assumes that the provided input stream has iterator_type that represents the iterator pointing to the next fragment of the fragmented underlying buffyer. This makes little sense if the input stream is a contiguous one (i.e. simple_memory_input_stream) so let's not make such assumptions. --- serializer_impl.hh | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) 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) {