From cd14b83192e45a34ab2774eafeba02f69fd66569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dziepak?= Date: Mon, 27 Feb 2017 16:59:27 +0000 Subject: [PATCH] idl: add start_frame() overload for seastar::simple_output_stream (cherry picked from commit 018d16d315caaf4036afebe0e451e1108624508d) (part of #2468) --- serialization_visitors.hh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/serialization_visitors.hh b/serialization_visitors.hh index e2857cda9b..4c59aa4186 100644 --- a/serialization_visitors.hh +++ b/serialization_visitors.hh @@ -115,4 +115,42 @@ inline frame start_frame(seastar::measuring_ou return { }; } +template<> +class place_holder { + seastar::simple_output_stream _substream; +public: + place_holder(seastar::simple_output_stream substream) + : _substream(substream) { } + + void set(seastar::simple_output_stream& out, size_type v) { + serialize(_substream, v); + } +}; + +template<> +class frame : public place_holder { + char* _start; +public: + frame(seastar::simple_output_stream ph, char* start) + : place_holder(ph), _start(start) { } + + void end(seastar::simple_output_stream& out) { + set(out, out.begin() - _start); + } +}; + +inline place_holder start_place_holder(seastar::simple_output_stream& out) { + return { out.write_substream(sizeof(size_type)) }; +} + +inline frame start_frame(seastar::simple_output_stream& out) { + auto start = out.begin(); + auto substream = out.write_substream(sizeof(size_type)); + { + auto sstr = substream; + serialize(sstr, size_type(0)); + } + return frame(substream, start); +} + }