2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_HTTP_IMPL_SERIALIZER_IPP
11 #define BOOST_BEAST_HTTP_IMPL_SERIALIZER_IPP
13 #include <boost/beast/core/detail/buffers_ref.hpp>
14 #include <boost/beast/http/error.hpp>
15 #include <boost/beast/http/status.hpp>
16 #include <boost/beast/core/detail/config.hpp>
17 #include <boost/assert.hpp>
25 bool isRequest, class Body, class Fields>
27 serializer<isRequest, Body, Fields>::
28 frdinit(std::true_type)
30 frd_.emplace(m_, m_.version(), m_.method());
34 bool isRequest, class Body, class Fields>
36 serializer<isRequest, Body, Fields>::
37 frdinit(std::false_type)
39 frd_.emplace(m_, m_.version(), m_.result_int());
43 bool isRequest, class Body, class Fields>
44 template<std::size_t I, class Visit>
47 serializer<isRequest, Body, Fields>::
48 do_visit(error_code& ec, Visit& visit)
50 pv_.template emplace<I>(limit_, v_.template get<I>());
51 visit(ec, beast::detail::make_buffers_ref(
52 pv_.template get<I>()));
55 //------------------------------------------------------------------------------
58 bool isRequest, class Body, class Fields>
59 serializer<isRequest, Body, Fields>::
60 serializer(value_type& m)
67 bool isRequest, class Body, class Fields>
70 serializer<isRequest, Body, Fields>::
71 next(error_code& ec, Visit&& visit)
73 using boost::asio::buffer_size;
78 frdinit(std::integral_constant<bool,
83 BOOST_BEAST_FALLTHROUGH;
93 auto result = rd_.get(ec);
94 if(ec == error::need_more)
100 more_ = result->second;
101 v_.template emplace<2>(
102 boost::in_place_init,
106 BOOST_BEAST_FALLTHROUGH;
110 do_visit<2>(ec, visit);
114 v_.template emplace<1>(frd_->get());
116 BOOST_BEAST_FALLTHROUGH;
118 do_visit<1>(ec, visit);
123 BOOST_BEAST_FALLTHROUGH;
127 auto result = rd_.get(ec);
132 more_ = result->second;
133 v_.template emplace<3>(result->first);
135 BOOST_BEAST_FALLTHROUGH;
139 do_visit<3>(ec, visit);
142 //----------------------------------------------------------------------
146 BOOST_BEAST_FALLTHROUGH;
153 goto go_header_only_c;
154 auto result = rd_.get(ec);
155 if(ec == error::need_more)
156 goto go_header_only_c;
160 goto go_header_only_c;
161 more_ = result->second;
164 // do it all in one buffer
165 v_.template emplace<7>(
166 boost::in_place_init,
168 buffer_size(result->first),
169 boost::asio::const_buffer{nullptr, 0},
173 detail::chunk_last(),
174 boost::asio::const_buffer{nullptr, 0},
178 v_.template emplace<4>(
179 boost::in_place_init,
181 buffer_size(result->first),
182 boost::asio::const_buffer{nullptr, 0},
187 BOOST_BEAST_FALLTHROUGH;
191 do_visit<4>(ec, visit);
195 v_.template emplace<1>(frd_->get());
196 s_ = do_header_only_c;
197 case do_header_only_c:
198 do_visit<1>(ec, visit);
203 BOOST_BEAST_FALLTHROUGH;
207 auto result = rd_.get(ec);
212 more_ = result->second;
215 // do it all in one buffer
216 v_.template emplace<6>(
217 boost::in_place_init,
218 buffer_size(result->first),
219 boost::asio::const_buffer{nullptr, 0},
223 detail::chunk_last(),
224 boost::asio::const_buffer{nullptr, 0},
226 goto go_body_final_c;
228 v_.template emplace<5>(
229 boost::in_place_init,
230 buffer_size(result->first),
231 boost::asio::const_buffer{nullptr, 0},
236 BOOST_BEAST_FALLTHROUGH;
240 do_visit<5>(ec, visit);
244 s_ = do_body_final_c;
245 BOOST_BEAST_FALLTHROUGH;
246 case do_body_final_c:
247 do_visit<6>(ec, visit);
252 BOOST_BEAST_FALLTHROUGH;
254 do_visit<7>(ec, visit);
259 v_.template emplace<8>(
260 boost::in_place_init,
261 detail::chunk_last(),
262 boost::asio::const_buffer{nullptr, 0},
265 BOOST_BEAST_FALLTHROUGH;
268 do_visit<8>(ec, visit);
271 //----------------------------------------------------------------------
285 bool isRequest, class Body, class Fields>
287 serializer<isRequest, Body, Fields>::
288 consume(std::size_t n)
290 using boost::asio::buffer_size;
295 n <= buffer_size(v_.template get<2>()));
296 v_.template get<2>().consume(n);
297 if(buffer_size(v_.template get<2>()) > 0)
308 n <= buffer_size(v_.template get<1>()));
309 v_.template get<1>().consume(n);
310 if(buffer_size(v_.template get<1>()) > 0)
322 n <= buffer_size(v_.template get<3>()));
323 v_.template get<3>().consume(n);
324 if(buffer_size(v_.template get<3>()) > 0)
333 //----------------------------------------------------------------------
337 n <= buffer_size(v_.template get<4>()));
338 v_.template get<4>().consume(n);
339 if(buffer_size(v_.template get<4>()) > 0)
349 case do_header_only_c:
352 n <= buffer_size(v_.template get<1>()));
353 v_.template get<1>().consume(n);
354 if(buffer_size(v_.template get<1>()) > 0)
369 n <= buffer_size(v_.template get<5>()));
370 v_.template get<5>().consume(n);
371 if(buffer_size(v_.template get<5>()) > 0)
380 case do_body_final_c:
383 n <= buffer_size(v_.template get<6>()));
384 v_.template get<6>().consume(n);
385 if(buffer_size(v_.template get<6>()) > 0)
395 n <= buffer_size(v_.template get<7>()));
396 v_.template get<7>().consume(n);
397 if(buffer_size(v_.template get<7>()) > 0)
406 BOOST_ASSERT(buffer_size(v_.template get<8>()));
407 v_.template get<8>().consume(n);
408 if(buffer_size(v_.template get<8>()) > 0)
413 //----------------------------------------------------------------------