ゴミ箱
serializer.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
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)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9 
10 #ifndef BOOST_BEAST_HTTP_SERIALIZER_HPP
11 #define BOOST_BEAST_HTTP_SERIALIZER_HPP
12 
13 #include <boost/beast/config.hpp>
22 #include <boost/asio/buffer.hpp>
23 #include <boost/optional.hpp>
24 
25 namespace boost {
26 namespace beast {
27 namespace http {
28 
56 template<
57  bool isRequest,
58  class Body,
59  class Fields = fields>
61 {
62 public:
63  static_assert(is_body<Body>::value,
64  "Body requirements not met");
65 
66  static_assert(is_body_reader<Body>::value,
67  "BodyReader requirements not met");
68 
74 #if BOOST_BEAST_DOXYGEN
75  using value_type = implementation_defined;
76 #else
77  using value_type =
78  typename std::conditional<
79  std::is_constructible<typename Body::reader,
81  ! std::is_constructible<typename Body::reader,
82  message<isRequest, Body, Fields> const&>::value,
84  message<isRequest, Body, Fields> const>::type;
85 #endif
86 
87 private:
88  enum
89  {
90  do_construct = 0,
91 
92  do_init = 10,
93  do_header_only = 20,
94  do_header = 30,
95  do_body = 40,
96 
97  do_init_c = 50,
98  do_header_only_c = 60,
99  do_header_c = 70,
100  do_body_c = 80,
101  do_final_c = 90,
102  #ifndef BOOST_BEAST_NO_BIG_VARIANTS
103  do_body_final_c = 100,
104  do_all_c = 110,
105  #endif
106 
107  do_complete = 120
108  };
109 
110  void frdinit(std::true_type);
111  void frdinit(std::false_type);
112 
113  template<std::size_t, class Visit>
114  void
115  do_visit(error_code& ec, Visit& visit);
116 
117  using reader = typename Body::reader;
118 
119  using cb1_t = consuming_buffers<typename
120  Fields::reader::const_buffers_type>; // header
122 
124  typename Fields::reader::const_buffers_type,// header
125  typename reader::const_buffers_type>>; // body
127 
128  using cb3_t = consuming_buffers<
129  typename reader::const_buffers_type>; // body
131 
133  typename Fields::reader::const_buffers_type,// header
134  detail::chunk_size, // chunk-size
135  boost::asio::const_buffers_1, // chunk-ext
136  chunk_crlf, // crlf
137  typename reader::const_buffers_type, // body
138  chunk_crlf>>; // crlf
140 
142  detail::chunk_size, // chunk-header
143  boost::asio::const_buffers_1, // chunk-ext
144  chunk_crlf, // crlf
145  typename reader::const_buffers_type, // body
146  chunk_crlf>>; // crlf
148 
150  detail::chunk_size, // chunk-header
151  boost::asio::const_buffers_1, // chunk-size
152  chunk_crlf, // crlf
153  typename reader::const_buffers_type, // body
154  chunk_crlf, // crlf
155  boost::asio::const_buffers_1, // chunk-final
156  boost::asio::const_buffers_1, // trailers
157  chunk_crlf>>; // crlf
159 
161  typename Fields::reader::const_buffers_type,// header
162  detail::chunk_size, // chunk-size
163  boost::asio::const_buffers_1, // chunk-ext
164  chunk_crlf, // crlf
165  typename reader::const_buffers_type, // body
166  chunk_crlf, // crlf
167  boost::asio::const_buffers_1, // chunk-final
168  boost::asio::const_buffers_1, // trailers
169  chunk_crlf>>; // crlf
171 
173  boost::asio::const_buffers_1, // chunk-final
174  boost::asio::const_buffers_1, // trailers
175  chunk_crlf>>; // crlf
177 
178  value_type& m_;
179  reader rd_;
180  boost::optional<typename Fields::reader> frd_;
182  cb1_t, cb2_t, cb3_t, cb4_t,
183  cb5_t ,cb6_t, cb7_t, cb8_t> v_;
186  pcb5_t ,pcb6_t, pcb7_t, pcb8_t> pv_;
187  std::size_t limit_ =
188  (std::numeric_limits<std::size_t>::max)();
189  int s_ = do_construct;
190  bool split_ = false;
191  bool header_done_ = false;
192  bool chunked_;
193  bool keep_alive_;
194  bool more_;
195 
196 public:
198  serializer(serializer&&) = default;
199 
201  serializer(serializer const&) = default;
202 
204  serializer& operator=(serializer const&) = delete;
205 
220  explicit
221  serializer(value_type& msg);
222 
224  value_type&
225  get()
226  {
227  return m_;
228  }
229 
231  std::size_t
233  {
234  return limit_;
235  }
236 
248  void
249  limit(std::size_t limit)
250  {
251  limit_ = limit > 0 ? limit :
252  (std::numeric_limits<std::size_t>::max)();
253  }
254 
257  bool
259  {
260  return split_;
261  }
262 
270  void
271  split(bool v)
272  {
273  split_ = v;
274  }
275 
281  bool
283  {
284  return header_done_;
285  }
286 
293  bool
295  {
296  return s_ == do_complete;
297  }
298 
304  bool
306  {
307  return chunked_;
308  }
309 
328  bool
330  {
331  return keep_alive_;
332  }
333 
358  template<class Visit>
359  void
360  next(error_code& ec, Visit&& visit);
361 
376  void
377  consume(std::size_t n);
378 
389  reader&
391  {
392  return rd_;
393  }
394 };
395 
397 template<class Body, class Fields = fields>
399 
401 template<class Body, class Fields = fields>
403 
404 } // http
405 } // beast
406 } // boost
407 
409 
410 #endif
void next(error_code &ec, Visit &&visit)
Definition: serializer.ipp:72
Definition: async_result.hpp:20
Definition: type_traits.hpp:25
Definition: consuming_buffers.hpp:40
bool is_header_done()
Definition: serializer.hpp:282
bool keep_alive()
Definition: serializer.hpp:329
Definition: beast_common.hpp:6
bool split()
Definition: serializer.hpp:258
serializer & operator=(serializer const &)=delete
Assignment.
serializer(serializer &&)=default
Constructor.
Definition: type_traits.hpp:79
boost::system::error_code error_code
The type of error code used by the library.
Definition: error.hpp:21
bool is_done()
Definition: serializer.hpp:294
reader & reader_impl()
Definition: serializer.hpp:390
Definition: buffer_cat.hpp:25
Definition: buffer_prefix.hpp:32
Definition: serializer.hpp:60
void consume(std::size_t n)
Definition: serializer.ipp:288
Definition: type_traits.hpp:73
Definition: variant.hpp:32
void split(bool v)
Definition: serializer.hpp:271
basic_fields< std::allocator< char >> fields
A typical HTTP header fields container.
Definition: fields.hpp:740
boost::asio::const_buffers_1 chunk_crlf()
Returns a buffer sequence holding a CRLF for chunk encoding.
Definition: chunk_encode.hpp:155
std::size_t limit()
Returns the serialized buffer size limit.
Definition: serializer.hpp:232
typename std::conditional< std::is_constructible< typename Body::reader, message< isRequest, Body, Fields > & >::value &&!std::is_constructible< typename Body::reader, message< isRequest, Body, Fields > const & >::value, message< isRequest, Body, Fields >, message< isRequest, Body, Fields > const >::type value_type
Definition: serializer.hpp:84
void limit(std::size_t limit)
Definition: serializer.hpp:249
bool chunked()
Definition: serializer.hpp:305
Definition: chunk_encode.hpp:68