62.85% Lines (247/393)
82.35% Functions (42/51)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | |||||
| 3 | // Copyright (c) 2024 Christian Mazakas | 3 | // Copyright (c) 2024 Christian Mazakas | |||||
| 4 | // Copyright (c) 2024 Mohammad Nejati | 4 | // Copyright (c) 2024 Mohammad Nejati | |||||
| 5 | // | 5 | // | |||||
| 6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||||
| 7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | 7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 8 | // | 8 | // | |||||
| 9 | // Official repository: https://github.com/cppalliance/http | 9 | // Official repository: https://github.com/cppalliance/http | |||||
| 10 | // | 10 | // | |||||
| 11 | 11 | |||||||
| 12 | #include <boost/http/detail/circular_buffer.hpp> | 12 | #include <boost/http/detail/circular_buffer.hpp> | |||||
| 13 | #include <boost/http/detail/except.hpp> | 13 | #include <boost/http/detail/except.hpp> | |||||
| 14 | #include <boost/http/detail/header.hpp> | 14 | #include <boost/http/detail/header.hpp> | |||||
| 15 | #include <boost/http/message_base.hpp> | 15 | #include <boost/http/message_base.hpp> | |||||
| 16 | #include <boost/http/serializer.hpp> | 16 | #include <boost/http/serializer.hpp> | |||||
| 17 | 17 | |||||||
| 18 | #include "src/detail/array_of_const_buffers.hpp" | 18 | #include "src/detail/array_of_const_buffers.hpp" | |||||
| 19 | #include "src/detail/brotli_filter_base.hpp" | 19 | #include "src/detail/brotli_filter_base.hpp" | |||||
| 20 | #include "src/detail/buffer_utils.hpp" | 20 | #include "src/detail/buffer_utils.hpp" | |||||
| 21 | #include "src/detail/zlib_filter_base.hpp" | 21 | #include "src/detail/zlib_filter_base.hpp" | |||||
| 22 | 22 | |||||||
| 23 | #include <boost/capy/buffers/buffer_copy.hpp> | 23 | #include <boost/capy/buffers/buffer_copy.hpp> | |||||
| 24 | #include <boost/capy/ex/system_context.hpp> | 24 | #include <boost/capy/ex/system_context.hpp> | |||||
| 25 | #include <boost/core/bit.hpp> | 25 | #include <boost/core/bit.hpp> | |||||
| 26 | #include <boost/core/ignore_unused.hpp> | 26 | #include <boost/core/ignore_unused.hpp> | |||||
| 27 | #include <boost/http/brotli/encode.hpp> | 27 | #include <boost/http/brotli/encode.hpp> | |||||
| 28 | #include <boost/http/zlib/compression_method.hpp> | 28 | #include <boost/http/zlib/compression_method.hpp> | |||||
| 29 | #include <boost/http/zlib/compression_strategy.hpp> | 29 | #include <boost/http/zlib/compression_strategy.hpp> | |||||
| 30 | #include <boost/http/zlib/deflate.hpp> | 30 | #include <boost/http/zlib/deflate.hpp> | |||||
| 31 | #include <boost/http/zlib/error.hpp> | 31 | #include <boost/http/zlib/error.hpp> | |||||
| 32 | #include <boost/http/zlib/flush.hpp> | 32 | #include <boost/http/zlib/flush.hpp> | |||||
| 33 | 33 | |||||||
| 34 | #include <array> | 34 | #include <array> | |||||
| 35 | #include <memory> | 35 | #include <memory> | |||||
| 36 | #include <stddef.h> | 36 | #include <stddef.h> | |||||
| 37 | 37 | |||||||
| 38 | namespace boost { | 38 | namespace boost { | |||||
| 39 | namespace http { | 39 | namespace http { | |||||
| 40 | 40 | |||||||
| 41 | namespace { | 41 | namespace { | |||||
| 42 | 42 | |||||||
| 43 | // Trim n bytes from the front of a 2-element buffer pair, in place. | 43 | // Trim n bytes from the front of a 2-element buffer pair, in place. | |||||
| 44 | // Replaces the pre-#262 `capy::remove_prefix(pair, n)` idiom on a | 44 | // Replaces the pre-#262 `capy::remove_prefix(pair, n)` idiom on a | |||||
| 45 | // 2-element buffer sequence. | 45 | // 2-element buffer sequence. | |||||
| 46 | template<class Buf> | 46 | template<class Buf> | |||||
| 47 | inline void | 47 | inline void | |||||
| HITCBC | 48 | 69 | trim_prefix_pair(std::array<Buf, 2>& a, std::size_t n) noexcept | 48 | 69 | trim_prefix_pair(std::array<Buf, 2>& a, std::size_t n) noexcept | ||
| 49 | { | 49 | { | |||||
| HITCBC | 50 | 69 | if(n >= a[0].size()) | 50 | 69 | if(n >= a[0].size()) | ||
| 51 | { | 51 | { | |||||
| MISUBC | 52 | ✗ | n -= a[0].size(); | 52 | ✗ | n -= a[0].size(); | ||
| MISUBC | 53 | ✗ | a[0] = Buf(); | 53 | ✗ | a[0] = Buf(); | ||
| MISUBC | 54 | ✗ | if(n >= a[1].size()) | 54 | ✗ | if(n >= a[1].size()) | ||
| MISUBC | 55 | ✗ | a[1] = Buf(); | 55 | ✗ | a[1] = Buf(); | ||
| 56 | else | 56 | else | |||||
| MISUBC | 57 | ✗ | a[1] = Buf( | 57 | ✗ | a[1] = Buf( | ||
| 58 | static_cast<char*>(const_cast<void*>( | 58 | static_cast<char*>(const_cast<void*>( | |||||
| MISUBC | 59 | ✗ | static_cast<void const*>(a[1].data()))) + n, | 59 | ✗ | static_cast<void const*>(a[1].data()))) + n, | ||
| MISUBC | 60 | ✗ | a[1].size() - n); | 60 | ✗ | a[1].size() - n); | ||
| 61 | } | 61 | } | |||||
| 62 | else | 62 | else | |||||
| 63 | { | 63 | { | |||||
| HITCBC | 64 | 69 | a[0] += n; | 64 | 69 | a[0] += n; | ||
| 65 | } | 65 | } | |||||
| HITCBC | 66 | 69 | } | 66 | 69 | } | ||
| 67 | 67 | |||||||
| 68 | // Trim n bytes from the back of a 2-element buffer pair, in place. | 68 | // Trim n bytes from the back of a 2-element buffer pair, in place. | |||||
| 69 | template<class Buf> | 69 | template<class Buf> | |||||
| 70 | inline void | 70 | inline void | |||||
| HITCBC | 71 | 69 | trim_suffix_pair(std::array<Buf, 2>& a, std::size_t n) noexcept | 71 | 69 | trim_suffix_pair(std::array<Buf, 2>& a, std::size_t n) noexcept | ||
| 72 | { | 72 | { | |||||
| HITCBC | 73 | 69 | if(n >= a[1].size()) | 73 | 69 | if(n >= a[1].size()) | ||
| 74 | { | 74 | { | |||||
| HITCBC | 75 | 69 | n -= a[1].size(); | 75 | 69 | n -= a[1].size(); | ||
| HITCBC | 76 | 69 | a[1] = Buf(); | 76 | 69 | a[1] = Buf(); | ||
| HITCBC | 77 | 69 | if(n >= a[0].size()) | 77 | 69 | if(n >= a[0].size()) | ||
| MISUBC | 78 | ✗ | a[0] = Buf(); | 78 | ✗ | a[0] = Buf(); | ||
| 79 | else | 79 | else | |||||
| HITCBC | 80 | 69 | a[0] = Buf(a[0].data(), a[0].size() - n); | 80 | 69 | a[0] = Buf(a[0].data(), a[0].size() - n); | ||
| 81 | } | 81 | } | |||||
| 82 | else | 82 | else | |||||
| 83 | { | 83 | { | |||||
| MISUBC | 84 | ✗ | a[1] = Buf(a[1].data(), a[1].size() - n); | 84 | ✗ | a[1] = Buf(a[1].data(), a[1].size() - n); | ||
| 85 | } | 85 | } | |||||
| HITCBC | 86 | 69 | } | 86 | 69 | } | ||
| 87 | 87 | |||||||
| 88 | const | 88 | const | |||||
| 89 | capy::const_buffer | 89 | capy::const_buffer | |||||
| 90 | crlf_and_final_chunk = {"\r\n0\r\n\r\n", 7}; | 90 | crlf_and_final_chunk = {"\r\n0\r\n\r\n", 7}; | |||||
| 91 | 91 | |||||||
| 92 | const | 92 | const | |||||
| 93 | capy::const_buffer | 93 | capy::const_buffer | |||||
| 94 | crlf = {"\r\n", 2}; | 94 | crlf = {"\r\n", 2}; | |||||
| 95 | 95 | |||||||
| 96 | const | 96 | const | |||||
| 97 | capy::const_buffer | 97 | capy::const_buffer | |||||
| 98 | final_chunk = {"0\r\n\r\n", 5}; | 98 | final_chunk = {"0\r\n\r\n", 5}; | |||||
| 99 | 99 | |||||||
| 100 | constexpr | 100 | constexpr | |||||
| 101 | std::uint8_t | 101 | std::uint8_t | |||||
| HITCBC | 102 | 159 | chunk_header_len( | 102 | 159 | chunk_header_len( | ||
| 103 | std::size_t max_chunk_size) noexcept | 103 | std::size_t max_chunk_size) noexcept | |||||
| 104 | { | 104 | { | |||||
| 105 | return | 105 | return | |||||
| 106 | static_cast<uint8_t>( | 106 | static_cast<uint8_t>( | |||||
| HITCBC | 107 | 159 | (core::bit_width(max_chunk_size) + 3) / 4 + | 107 | 159 | (core::bit_width(max_chunk_size) + 3) / 4 + | ||
| HITCBC | 108 | 159 | 2); // crlf | 108 | 159 | 2); // crlf | ||
| 109 | }; | 109 | }; | |||||
| 110 | 110 | |||||||
| 111 | void | 111 | void | |||||
| HITCBC | 112 | 68 | write_chunk_header( | 112 | 68 | write_chunk_header( | ||
| 113 | const std::array<capy::mutable_buffer, 2>& mbs, | 113 | const std::array<capy::mutable_buffer, 2>& mbs, | |||||
| 114 | std::size_t size) noexcept | 114 | std::size_t size) noexcept | |||||
| 115 | { | 115 | { | |||||
| 116 | static constexpr char hexdig[] = | 116 | static constexpr char hexdig[] = | |||||
| 117 | "0123456789ABCDEF"; | 117 | "0123456789ABCDEF"; | |||||
| 118 | char buf[18]; | 118 | char buf[18]; | |||||
| HITCBC | 119 | 68 | auto p = buf + 16; | 119 | 68 | auto p = buf + 16; | ||
| HITCBC | 120 | 68 | auto const n = capy::buffer_size(mbs); | 120 | 68 | auto const n = capy::buffer_size(mbs); | ||
| HITCBC | 121 | 340 | for(std::size_t i = n - 2; i--;) | 121 | 340 | for(std::size_t i = n - 2; i--;) | ||
| 122 | { | 122 | { | |||||
| HITCBC | 123 | 272 | *--p = hexdig[size & 0xf]; | 123 | 272 | *--p = hexdig[size & 0xf]; | ||
| HITCBC | 124 | 272 | size >>= 4; | 124 | 272 | size >>= 4; | ||
| 125 | } | 125 | } | |||||
| HITCBC | 126 | 68 | buf[16] = '\r'; | 126 | 68 | buf[16] = '\r'; | ||
| HITCBC | 127 | 68 | buf[17] = '\n'; | 127 | 68 | buf[17] = '\n'; | ||
| HITCBC | 128 | 68 | auto copied = capy::buffer_copy( | 128 | 68 | auto copied = capy::buffer_copy( | ||
| 129 | mbs, | 129 | mbs, | |||||
| HITCBC | 130 | 136 | capy::const_buffer(p, n)); | 130 | 136 | capy::const_buffer(p, n)); | ||
| 131 | ignore_unused(copied); | 131 | ignore_unused(copied); | |||||
| HITCBC | 132 | 68 | BOOST_ASSERT(copied == n); | 132 | 68 | BOOST_ASSERT(copied == n); | ||
| HITCBC | 133 | 68 | } | 133 | 68 | } | ||
| 134 | 134 | |||||||
| 135 | class zlib_filter | 135 | class zlib_filter | |||||
| 136 | : public detail::zlib_filter_base | 136 | : public detail::zlib_filter_base | |||||
| 137 | { | 137 | { | |||||
| 138 | http::zlib::deflate_service& svc_; | 138 | http::zlib::deflate_service& svc_; | |||||
| 139 | 139 | |||||||
| 140 | public: | 140 | public: | |||||
| MISUBC | 141 | ✗ | zlib_filter( | 141 | ✗ | zlib_filter( | ||
| 142 | http::zlib::deflate_service& svc, | 142 | http::zlib::deflate_service& svc, | |||||
| 143 | int comp_level, | 143 | int comp_level, | |||||
| 144 | int window_bits, | 144 | int window_bits, | |||||
| 145 | int mem_level) | 145 | int mem_level) | |||||
| MISUBC | 146 | ✗ | : svc_(svc) | 146 | ✗ | : svc_(svc) | ||
| 147 | { | 147 | { | |||||
| MISUBC | 148 | - | ✗ | system::error_code ec = static_cast<http::zlib::error>(svc_.init2( | 148 | + | ✗ | std::error_code ec = static_cast<http::zlib::error>(svc_.init2( |
| MISUBC | 149 | ✗ | strm_, | 149 | ✗ | strm_, | ||
| 150 | comp_level, | 150 | comp_level, | |||||
| 151 | http::zlib::deflated, | 151 | http::zlib::deflated, | |||||
| 152 | window_bits, | 152 | window_bits, | |||||
| 153 | mem_level, | 153 | mem_level, | |||||
| MISUBC | 154 | ✗ | http::zlib::default_strategy)); | 154 | ✗ | http::zlib::default_strategy)); | ||
| MISUBC | 155 | ✗ | if(ec != http::zlib::error::ok) | 155 | ✗ | if(ec != http::zlib::error::ok) | ||
| MISUBC | 156 | ✗ | detail::throw_system_error(ec); | 156 | ✗ | detail::throw_system_error(ec); | ||
| MISUBC | 157 | ✗ | } | 157 | ✗ | } | ||
| 158 | 158 | |||||||
| 159 | private: | 159 | private: | |||||
| 160 | virtual | 160 | virtual | |||||
| 161 | std::size_t | 161 | std::size_t | |||||
| MISUBC | 162 | ✗ | min_out_buffer() const noexcept override | 162 | ✗ | min_out_buffer() const noexcept override | ||
| 163 | { | 163 | { | |||||
| MISUBC | 164 | ✗ | return 8; | 164 | ✗ | return 8; | ||
| 165 | } | 165 | } | |||||
| 166 | 166 | |||||||
| 167 | virtual | 167 | virtual | |||||
| 168 | results | 168 | results | |||||
| MISUBC | 169 | ✗ | do_process( | 169 | ✗ | do_process( | ||
| 170 | capy::mutable_buffer out, | 170 | capy::mutable_buffer out, | |||||
| 171 | capy::const_buffer in, | 171 | capy::const_buffer in, | |||||
| 172 | bool more) noexcept override | 172 | bool more) noexcept override | |||||
| 173 | { | 173 | { | |||||
| MISUBC | 174 | ✗ | strm_.next_out = static_cast<unsigned char*>(out.data()); | 174 | ✗ | strm_.next_out = static_cast<unsigned char*>(out.data()); | ||
| MISUBC | 175 | ✗ | strm_.avail_out = saturate_cast(out.size()); | 175 | ✗ | strm_.avail_out = saturate_cast(out.size()); | ||
| MISUBC | 176 | ✗ | strm_.next_in = static_cast<unsigned char*>(const_cast<void *>(in.data())); | 176 | ✗ | strm_.next_in = static_cast<unsigned char*>(const_cast<void *>(in.data())); | ||
| MISUBC | 177 | ✗ | strm_.avail_in = saturate_cast(in.size()); | 177 | ✗ | strm_.avail_in = saturate_cast(in.size()); | ||
| 178 | 178 | |||||||
| 179 | auto rs = static_cast<http::zlib::error>( | 179 | auto rs = static_cast<http::zlib::error>( | |||||
| MISUBC | 180 | ✗ | svc_.deflate( | 180 | ✗ | svc_.deflate( | ||
| MISUBC | 181 | ✗ | strm_, | 181 | ✗ | strm_, | ||
| 182 | more ? http::zlib::no_flush : http::zlib::finish)); | 182 | more ? http::zlib::no_flush : http::zlib::finish)); | |||||
| 183 | 183 | |||||||
| MISUBC | 184 | ✗ | results rv; | 184 | ✗ | results rv; | ||
| MISUBC | 185 | ✗ | rv.out_bytes = saturate_cast(out.size()) - strm_.avail_out; | 185 | ✗ | rv.out_bytes = saturate_cast(out.size()) - strm_.avail_out; | ||
| MISUBC | 186 | ✗ | rv.in_bytes = saturate_cast(in.size()) - strm_.avail_in; | 186 | ✗ | rv.in_bytes = saturate_cast(in.size()) - strm_.avail_in; | ||
| MISUBC | 187 | ✗ | rv.finished = (rs == http::zlib::error::stream_end); | 187 | ✗ | rv.finished = (rs == http::zlib::error::stream_end); | ||
| 188 | 188 | |||||||
| MISUBC | 189 | ✗ | if(rs < http::zlib::error::ok && rs != http::zlib::error::buf_err) | 189 | ✗ | if(rs < http::zlib::error::ok && rs != http::zlib::error::buf_err) | ||
| MISUBC | 190 | ✗ | rv.ec = rs; | 190 | ✗ | rv.ec = rs; | ||
| 191 | 191 | |||||||
| MISUBC | 192 | ✗ | return rv; | 192 | ✗ | return rv; | ||
| 193 | } | 193 | } | |||||
| 194 | }; | 194 | }; | |||||
| 195 | 195 | |||||||
| 196 | class brotli_filter | 196 | class brotli_filter | |||||
| 197 | : public detail::brotli_filter_base | 197 | : public detail::brotli_filter_base | |||||
| 198 | { | 198 | { | |||||
| 199 | http::brotli::encode_service& svc_; | 199 | http::brotli::encode_service& svc_; | |||||
| 200 | http::brotli::encoder_state* state_; | 200 | http::brotli::encoder_state* state_; | |||||
| 201 | 201 | |||||||
| 202 | public: | 202 | public: | |||||
| MISUBC | 203 | ✗ | brotli_filter( | 203 | ✗ | brotli_filter( | ||
| 204 | http::brotli::encode_service& svc, | 204 | http::brotli::encode_service& svc, | |||||
| 205 | std::uint32_t comp_quality, | 205 | std::uint32_t comp_quality, | |||||
| 206 | std::uint32_t comp_window) | 206 | std::uint32_t comp_window) | |||||
| MISUBC | 207 | ✗ | : svc_(svc) | 207 | ✗ | : svc_(svc) | ||
| 208 | { | 208 | { | |||||
| MISUBC | 209 | ✗ | state_ = svc_.create_instance(nullptr, nullptr, nullptr); | 209 | ✗ | state_ = svc_.create_instance(nullptr, nullptr, nullptr); | ||
| MISUBC | 210 | ✗ | if(!state_) | 210 | ✗ | if(!state_) | ||
| MISUBC | 211 | ✗ | detail::throw_bad_alloc(); | 211 | ✗ | detail::throw_bad_alloc(); | ||
| 212 | using encoder_parameter = http::brotli::encoder_parameter; | 212 | using encoder_parameter = http::brotli::encoder_parameter; | |||||
| MISUBC | 213 | ✗ | svc_.set_parameter(state_, encoder_parameter::quality, comp_quality); | 213 | ✗ | svc_.set_parameter(state_, encoder_parameter::quality, comp_quality); | ||
| MISUBC | 214 | ✗ | svc_.set_parameter(state_, encoder_parameter::lgwin, comp_window); | 214 | ✗ | svc_.set_parameter(state_, encoder_parameter::lgwin, comp_window); | ||
| MISUBC | 215 | ✗ | } | 215 | ✗ | } | ||
| 216 | 216 | |||||||
| MISUBC | 217 | ✗ | ~brotli_filter() | 217 | ✗ | ~brotli_filter() | ||
| MISUBC | 218 | ✗ | { | 218 | ✗ | { | ||
| MISUBC | 219 | ✗ | svc_.destroy_instance(state_); | 219 | ✗ | svc_.destroy_instance(state_); | ||
| MISUBC | 220 | ✗ | } | 220 | ✗ | } | ||
| 221 | 221 | |||||||
| 222 | private: | 222 | private: | |||||
| 223 | virtual | 223 | virtual | |||||
| 224 | results | 224 | results | |||||
| MISUBC | 225 | ✗ | do_process( | 225 | ✗ | do_process( | ||
| 226 | capy::mutable_buffer out, | 226 | capy::mutable_buffer out, | |||||
| 227 | capy::const_buffer in, | 227 | capy::const_buffer in, | |||||
| 228 | bool more) noexcept override | 228 | bool more) noexcept override | |||||
| 229 | { | 229 | { | |||||
| MISUBC | 230 | ✗ | auto* next_in = reinterpret_cast<const std::uint8_t*>(in.data()); | 230 | ✗ | auto* next_in = reinterpret_cast<const std::uint8_t*>(in.data()); | ||
| MISUBC | 231 | ✗ | auto available_in = in.size(); | 231 | ✗ | auto available_in = in.size(); | ||
| MISUBC | 232 | ✗ | auto* next_out = reinterpret_cast<std::uint8_t*>(out.data()); | 232 | ✗ | auto* next_out = reinterpret_cast<std::uint8_t*>(out.data()); | ||
| MISUBC | 233 | ✗ | auto available_out = out.size(); | 233 | ✗ | auto available_out = out.size(); | ||
| 234 | 234 | |||||||
| 235 | using encoder_operation = | 235 | using encoder_operation = | |||||
| 236 | http::brotli::encoder_operation; | 236 | http::brotli::encoder_operation; | |||||
| 237 | 237 | |||||||
| MISUBC | 238 | ✗ | bool rs = svc_.compress_stream( | 238 | ✗ | bool rs = svc_.compress_stream( | ||
| 239 | state_, | 239 | state_, | |||||
| 240 | more ? encoder_operation::process : encoder_operation::finish, | 240 | more ? encoder_operation::process : encoder_operation::finish, | |||||
| 241 | &available_in, | 241 | &available_in, | |||||
| 242 | &next_in, | 242 | &next_in, | |||||
| 243 | &available_out, | 243 | &available_out, | |||||
| 244 | &next_out, | 244 | &next_out, | |||||
| 245 | nullptr); | 245 | nullptr); | |||||
| 246 | 246 | |||||||
| MISUBC | 247 | ✗ | results rv; | 247 | ✗ | results rv; | ||
| MISUBC | 248 | ✗ | rv.in_bytes = in.size() - available_in; | 248 | ✗ | rv.in_bytes = in.size() - available_in; | ||
| MISUBC | 249 | ✗ | rv.out_bytes = out.size() - available_out; | 249 | ✗ | rv.out_bytes = out.size() - available_out; | ||
| MISUBC | 250 | ✗ | rv.finished = svc_.is_finished(state_); | 250 | ✗ | rv.finished = svc_.is_finished(state_); | ||
| 251 | 251 | |||||||
| MISUBC | 252 | ✗ | if(rs == false) | 252 | ✗ | if(rs == false) | ||
| MISUBC | 253 | ✗ | rv.ec = error::bad_payload; | 253 | ✗ | rv.ec = error::bad_payload; | ||
| 254 | 254 | |||||||
| MISUBC | 255 | ✗ | return rv; | 255 | ✗ | return rv; | ||
| 256 | } | 256 | } | |||||
| 257 | }; | 257 | }; | |||||
| 258 | 258 | |||||||
| 259 | template<class UInt> | 259 | template<class UInt> | |||||
| 260 | std::size_t | 260 | std::size_t | |||||
| 261 | clamp( | 261 | clamp( | |||||
| 262 | UInt x, | 262 | UInt x, | |||||
| 263 | std::size_t limit = (std::numeric_limits< | 263 | std::size_t limit = (std::numeric_limits< | |||||
| 264 | std::size_t>::max)()) noexcept | 264 | std::size_t>::max)()) noexcept | |||||
| 265 | { | 265 | { | |||||
| 266 | if(x >= limit) | 266 | if(x >= limit) | |||||
| 267 | return limit; | 267 | return limit; | |||||
| 268 | return static_cast<std::size_t>(x); | 268 | return static_cast<std::size_t>(x); | |||||
| 269 | } | 269 | } | |||||
| 270 | 270 | |||||||
| 271 | } // namespace | 271 | } // namespace | |||||
| 272 | 272 | |||||||
| 273 | //------------------------------------------------ | 273 | //------------------------------------------------ | |||||
| 274 | 274 | |||||||
| 275 | class serializer::impl | 275 | class serializer::impl | |||||
| 276 | { | 276 | { | |||||
| 277 | enum class state | 277 | enum class state | |||||
| 278 | { | 278 | { | |||||
| 279 | reset, | 279 | reset, | |||||
| 280 | start, | 280 | start, | |||||
| 281 | header, | 281 | header, | |||||
| 282 | body | 282 | body | |||||
| 283 | }; | 283 | }; | |||||
| 284 | 284 | |||||||
| 285 | enum class style | 285 | enum class style | |||||
| 286 | { | 286 | { | |||||
| 287 | empty, | 287 | empty, | |||||
| 288 | stream | 288 | stream | |||||
| 289 | }; | 289 | }; | |||||
| 290 | 290 | |||||||
| 291 | std::shared_ptr<serializer_config_impl const> cfg_; | 291 | std::shared_ptr<serializer_config_impl const> cfg_; | |||||
| 292 | detail::workspace ws_; | 292 | detail::workspace ws_; | |||||
| 293 | 293 | |||||||
| 294 | std::unique_ptr<detail::filter> filter_; | 294 | std::unique_ptr<detail::filter> filter_; | |||||
| 295 | 295 | |||||||
| 296 | detail::circular_buffer out_; | 296 | detail::circular_buffer out_; | |||||
| 297 | detail::circular_buffer in_; | 297 | detail::circular_buffer in_; | |||||
| 298 | detail::array_of_const_buffers prepped_; | 298 | detail::array_of_const_buffers prepped_; | |||||
| 299 | capy::const_buffer tmp_; | 299 | capy::const_buffer tmp_; | |||||
| 300 | 300 | |||||||
| 301 | state state_ = state::start; | 301 | state state_ = state::start; | |||||
| 302 | style style_ = style::empty; | 302 | style style_ = style::empty; | |||||
| 303 | uint8_t chunk_header_len_ = 0; | 303 | uint8_t chunk_header_len_ = 0; | |||||
| 304 | bool more_input_ = false; | 304 | bool more_input_ = false; | |||||
| 305 | bool is_chunked_ = false; | 305 | bool is_chunked_ = false; | |||||
| 306 | bool needs_exp100_continue_ = false; | 306 | bool needs_exp100_continue_ = false; | |||||
| 307 | bool filter_done_ = false; | 307 | bool filter_done_ = false; | |||||
| 308 | 308 | |||||||
| 309 | public: | 309 | public: | |||||
| 310 | message_base const* msg_ = nullptr; | 310 | message_base const* msg_ = nullptr; | |||||
| 311 | 311 | |||||||
| 312 | explicit | 312 | explicit | |||||
| HITCBC | 313 | 158 | impl(std::shared_ptr<serializer_config_impl const> cfg) | 313 | 158 | impl(std::shared_ptr<serializer_config_impl const> cfg) | ||
| HITCBC | 314 | 158 | : cfg_(std::move(cfg)) | 314 | 158 | : cfg_(std::move(cfg)) | ||
| HITCBC | 315 | 158 | , ws_(cfg_->space_needed) | 315 | 158 | , ws_(cfg_->space_needed) | ||
| 316 | { | 316 | { | |||||
| HITCBC | 317 | 158 | } | 317 | 158 | } | ||
| 318 | 318 | |||||||
| 319 | impl( | 319 | impl( | |||||
| 320 | std::shared_ptr<serializer_config_impl const> cfg, | 320 | std::shared_ptr<serializer_config_impl const> cfg, | |||||
| 321 | message_base const& msg) | 321 | message_base const& msg) | |||||
| 322 | : cfg_(std::move(cfg)) | 322 | : cfg_(std::move(cfg)) | |||||
| 323 | , ws_(cfg_->space_needed) | 323 | , ws_(cfg_->space_needed) | |||||
| 324 | , msg_(&msg) | 324 | , msg_(&msg) | |||||
| 325 | { | 325 | { | |||||
| 326 | } | 326 | } | |||||
| 327 | 327 | |||||||
| 328 | void | 328 | void | |||||
| HITCBC | 329 | 54 | reset() noexcept | 329 | 54 | reset() noexcept | ||
| 330 | { | 330 | { | |||||
| HITCBC | 331 | 54 | filter_.reset(); | 331 | 54 | filter_.reset(); | ||
| HITCBC | 332 | 54 | ws_.clear(); | 332 | 54 | ws_.clear(); | ||
| HITCBC | 333 | 54 | state_ = state::start; | 333 | 54 | state_ = state::start; | ||
| HITCBC | 334 | 54 | } | 334 | 54 | } | ||
| 335 | 335 | |||||||
| 336 | auto | 336 | auto | |||||
| HITCBC | 337 | 389 | prepare() -> | 337 | 389 | prepare() -> | ||
| 338 | system::result<const_buffers_type> | 338 | system::result<const_buffers_type> | |||||
| 339 | { | 339 | { | |||||
| 340 | // Precondition violation | 340 | // Precondition violation | |||||
| HITCBC | 341 | 389 | if(state_ < state::header) | 341 | 389 | if(state_ < state::header) | ||
| HITCBC | 342 | 1 | detail::throw_logic_error(); | 342 | 1 | detail::throw_logic_error(); | ||
| 343 | 343 | |||||||
| 344 | // Expect: 100-continue | 344 | // Expect: 100-continue | |||||
| HITCBC | 345 | 388 | if(needs_exp100_continue_) | 345 | 388 | if(needs_exp100_continue_) | ||
| 346 | { | 346 | { | |||||
| HITCBC | 347 | 4 | if(!is_header_done()) | 347 | 4 | if(!is_header_done()) | ||
| HITCBC | 348 | 4 | return const_buffers_type( | 348 | 4 | return const_buffers_type( | ||
| 349 | prepped_.begin(), | 349 | prepped_.begin(), | |||||
| HITCBC | 350 | 2 | 1); // limit to header | 350 | 2 | 1); // limit to header | ||
| 351 | 351 | |||||||
| HITCBC | 352 | 2 | needs_exp100_continue_ = false; | 352 | 2 | needs_exp100_continue_ = false; | ||
| 353 | 353 | |||||||
| HITCBC | 354 | - | 2 | BOOST_HTTP_RETURN_EC( | 354 | + | 2 | return error::expect_100_continue; |
| 355 | - | error::expect_100_continue); | ||||||
| 356 | } | 355 | } | |||||
| 357 | 356 | |||||||
| HITCBC | 358 | 384 | if(!filter_) | 357 | 384 | if(!filter_) | ||
| 359 | { | 358 | { | |||||
| HITCBC | 360 | 384 | switch(style_) | 359 | 384 | switch(style_) | ||
| 361 | { | 360 | { | |||||
| HITCBC | 362 | 6 | case style::empty: | 361 | 6 | case style::empty: | ||
| HITCBC | 363 | 6 | break; | 362 | 6 | break; | ||
| 364 | 363 | |||||||
| HITCBC | 365 | 378 | case style::stream: | 364 | 378 | case style::stream: | ||
| HITCBC | 366 | 378 | if(out_.size() == 0 && is_header_done() && more_input_) | 365 | 378 | if(out_.size() == 0 && is_header_done() && more_input_) | ||
| HITCBC | 367 | - | 118 | BOOST_HTTP_RETURN_EC( | 366 | + | 118 | return error::need_data; |
| 368 | - | error::need_data); | ||||||
| HITCBC | 369 | 260 | break; | 367 | 260 | break; | ||
| 370 | } | 368 | } | |||||
| 371 | } | 369 | } | |||||
| 372 | else // filter | 370 | else // filter | |||||
| 373 | { | 371 | { | |||||
| MISUBC | 374 | ✗ | switch(style_) | 372 | ✗ | switch(style_) | ||
| 375 | { | 373 | { | |||||
| MISUBC | 376 | ✗ | case style::empty: | 374 | ✗ | case style::empty: | ||
| 377 | { | 375 | { | |||||
| MISUBC | 378 | ✗ | if(out_capacity() == 0 || filter_done_) | 376 | ✗ | if(out_capacity() == 0 || filter_done_) | ||
| MISUBC | 379 | ✗ | break; | 377 | ✗ | break; | ||
| 380 | 378 | |||||||
| MISUBC | 381 | ✗ | const auto rs = filter_->process( | 379 | ✗ | const auto rs = filter_->process( | ||
| MISUBC | 382 | ✗ | detail::make_span(out_prepare()), | 380 | ✗ | detail::make_span(out_prepare()), | ||
| 383 | {}, // empty input | 381 | {}, // empty input | |||||
| 384 | false); | 382 | false); | |||||
| 385 | 383 | |||||||
| MISUBC | 386 | ✗ | if(rs.ec) | 384 | ✗ | if(rs.ec) | ||
| 387 | { | 385 | { | |||||
| MISUBC | 388 | ✗ | ws_.clear(); | 386 | ✗ | ws_.clear(); | ||
| MISUBC | 389 | ✗ | state_ = state::reset; | 387 | ✗ | state_ = state::reset; | ||
| MISUBC | 390 | ✗ | return rs.ec; | 388 | ✗ | return rs.ec; | ||
| 391 | } | 389 | } | |||||
| 392 | 390 | |||||||
| MISUBC | 393 | ✗ | out_commit(rs.out_bytes); | 391 | ✗ | out_commit(rs.out_bytes); | ||
| 394 | 392 | |||||||
| MISUBC | 395 | ✗ | if(rs.finished) | 393 | ✗ | if(rs.finished) | ||
| 396 | { | 394 | { | |||||
| MISUBC | 397 | ✗ | filter_done_ = true; | 395 | ✗ | filter_done_ = true; | ||
| MISUBC | 398 | ✗ | out_finish(); | 396 | ✗ | out_finish(); | ||
| 399 | } | 397 | } | |||||
| 400 | 398 | |||||||
| MISUBC | 401 | ✗ | break; | 399 | ✗ | break; | ||
| 402 | } | 400 | } | |||||
| 403 | 401 | |||||||
| MISUBC | 404 | ✗ | case style::stream: | 402 | ✗ | case style::stream: | ||
| 405 | { | 403 | { | |||||
| MISUBC | 406 | ✗ | if(out_capacity() == 0 || filter_done_) | 404 | ✗ | if(out_capacity() == 0 || filter_done_) | ||
| MISUBC | 407 | ✗ | break; | 405 | ✗ | break; | ||
| 408 | 406 | |||||||
| MISUBC | 409 | ✗ | const auto rs = filter_->process( | 407 | ✗ | const auto rs = filter_->process( | ||
| MISUBC | 410 | ✗ | detail::make_span(out_prepare()), | 408 | ✗ | detail::make_span(out_prepare()), | ||
| 411 | in_.data(), | 409 | in_.data(), | |||||
| MISUBC | 412 | ✗ | more_input_); | 410 | ✗ | more_input_); | ||
| 413 | 411 | |||||||
| MISUBC | 414 | ✗ | if(rs.ec) | 412 | ✗ | if(rs.ec) | ||
| 415 | { | 413 | { | |||||
| MISUBC | 416 | ✗ | ws_.clear(); | 414 | ✗ | ws_.clear(); | ||
| MISUBC | 417 | ✗ | state_ = state::reset; | 415 | ✗ | state_ = state::reset; | ||
| MISUBC | 418 | ✗ | return rs.ec; | 416 | ✗ | return rs.ec; | ||
| 419 | } | 417 | } | |||||
| 420 | 418 | |||||||
| MISUBC | 421 | ✗ | in_.consume(rs.in_bytes); | 419 | ✗ | in_.consume(rs.in_bytes); | ||
| MISUBC | 422 | ✗ | out_commit(rs.out_bytes); | 420 | ✗ | out_commit(rs.out_bytes); | ||
| 423 | 421 | |||||||
| MISUBC | 424 | ✗ | if(rs.finished) | 422 | ✗ | if(rs.finished) | ||
| 425 | { | 423 | { | |||||
| MISUBC | 426 | ✗ | filter_done_ = true; | 424 | ✗ | filter_done_ = true; | ||
| MISUBC | 427 | ✗ | out_finish(); | 425 | ✗ | out_finish(); | ||
| 428 | } | 426 | } | |||||
| 429 | 427 | |||||||
| MISUBC | 430 | ✗ | if(out_.size() == 0 && is_header_done() && more_input_) | 428 | ✗ | if(out_.size() == 0 && is_header_done() && more_input_) | ||
| MISUBC | 431 | - | ✗ | BOOST_HTTP_RETURN_EC( | 429 | + | ✗ | return error::need_data; |
| 432 | - | error::need_data); | ||||||
| MISUBC | 433 | ✗ | break; | 430 | ✗ | break; | ||
| 434 | } | 431 | } | |||||
| 435 | } | 432 | } | |||||
| 436 | } | 433 | } | |||||
| 437 | 434 | |||||||
| HITCBC | 438 | 266 | prepped_.reset(!is_header_done()); | 435 | 266 | prepped_.reset(!is_header_done()); | ||
| HITCBC | 439 | 798 | for(auto const& cb : out_.data()) | 436 | 798 | for(auto const& cb : out_.data()) | ||
| 440 | { | 437 | { | |||||
| HITCBC | 441 | 532 | if(cb.size() != 0) | 438 | 532 | if(cb.size() != 0) | ||
| HITCBC | 442 | 168 | prepped_.append(cb); | 439 | 168 | prepped_.append(cb); | ||
| 443 | } | 440 | } | |||||
| HITCBC | 444 | 266 | return detail::make_span(prepped_); | 441 | 266 | return detail::make_span(prepped_); | ||
| 445 | } | 442 | } | |||||
| 446 | 443 | |||||||
| 447 | void | 444 | void | |||||
| HITCBC | 448 | 1902 | consume( | 445 | 1902 | consume( | ||
| 449 | std::size_t n) | 446 | std::size_t n) | |||||
| 450 | { | 447 | { | |||||
| 451 | // Precondition violation | 448 | // Precondition violation | |||||
| HITCBC | 452 | 1902 | if(state_ < state::header) | 449 | 1902 | if(state_ < state::header) | ||
| HITCBC | 453 | 1 | detail::throw_logic_error(); | 450 | 1 | detail::throw_logic_error(); | ||
| 454 | 451 | |||||||
| HITCBC | 455 | 1901 | if(!is_header_done()) | 452 | 1901 | if(!is_header_done()) | ||
| 456 | { | 453 | { | |||||
| 457 | const auto header_remain = | 454 | const auto header_remain = | |||||
| HITCBC | 458 | 132 | prepped_[0].size(); | 455 | 132 | prepped_[0].size(); | ||
| HITCBC | 459 | 132 | if(n < header_remain) | 456 | 132 | if(n < header_remain) | ||
| 460 | { | 457 | { | |||||
| HITCBC | 461 | 48 | prepped_.consume(n); | 458 | 48 | prepped_.consume(n); | ||
| HITCBC | 462 | 48 | return; | 459 | 48 | return; | ||
| 463 | } | 460 | } | |||||
| HITCBC | 464 | 84 | n -= header_remain; | 461 | 84 | n -= header_remain; | ||
| HITCBC | 465 | 84 | prepped_.consume(header_remain); | 462 | 84 | prepped_.consume(header_remain); | ||
| HITCBC | 466 | 84 | state_ = state::body; | 463 | 84 | state_ = state::body; | ||
| 467 | } | 464 | } | |||||
| 468 | 465 | |||||||
| HITCBC | 469 | 1853 | prepped_.consume(n); | 466 | 1853 | prepped_.consume(n); | ||
| 470 | 467 | |||||||
| 471 | // no-op when out_ is not in use | 468 | // no-op when out_ is not in use | |||||
| HITCBC | 472 | 1853 | out_.consume(n); | 469 | 1853 | out_.consume(n); | ||
| 473 | 470 | |||||||
| HITCBC | 474 | 1853 | if(!prepped_.empty()) | 471 | 1853 | if(!prepped_.empty()) | ||
| HITCBC | 475 | 1692 | return; | 472 | 1692 | return; | ||
| 476 | 473 | |||||||
| HITCBC | 477 | 161 | if(more_input_) | 474 | 161 | if(more_input_) | ||
| HITCBC | 478 | 109 | return; | 475 | 109 | return; | ||
| 479 | 476 | |||||||
| HITCBC | 480 | 52 | if(filter_ && !filter_done_) | 477 | 52 | if(filter_ && !filter_done_) | ||
| MISUBC | 481 | ✗ | return; | 478 | ✗ | return; | ||
| 482 | 479 | |||||||
| HITCBC | 483 | 52 | if(needs_exp100_continue_) | 480 | 52 | if(needs_exp100_continue_) | ||
| HITCBC | 484 | 2 | return; | 481 | 2 | return; | ||
| 485 | 482 | |||||||
| 486 | // ready for next message | 483 | // ready for next message | |||||
| HITCBC | 487 | 50 | reset(); | 484 | 50 | reset(); | ||
| 488 | } | 485 | } | |||||
| 489 | 486 | |||||||
| 490 | void | 487 | void | |||||
| HITCBC | 491 | 159 | start_init( | 488 | 159 | start_init( | ||
| 492 | message_base const& m) | 489 | message_base const& m) | |||||
| 493 | { | 490 | { | |||||
| 494 | // Precondition violation | 491 | // Precondition violation | |||||
| HITCBC | 495 | 159 | if(state_ != state::start) | 492 | 159 | if(state_ != state::start) | ||
| MISUBC | 496 | ✗ | detail::throw_logic_error(); | 493 | ✗ | detail::throw_logic_error(); | ||
| 497 | 494 | |||||||
| 498 | // TODO: To uphold the strong exception guarantee, | 495 | // TODO: To uphold the strong exception guarantee, | |||||
| 499 | // `state_` must be reset to `state::start` if an | 496 | // `state_` must be reset to `state::start` if an | |||||
| 500 | // exception is thrown during the start operation. | 497 | // exception is thrown during the start operation. | |||||
| HITCBC | 501 | 159 | state_ = state::header; | 498 | 159 | state_ = state::header; | ||
| 502 | 499 | |||||||
| 503 | // VFALCO what do we do with | 500 | // VFALCO what do we do with | |||||
| 504 | // metadata error code failures? | 501 | // metadata error code failures? | |||||
| 505 | // m.h_.md.maybe_throw(); | 502 | // m.h_.md.maybe_throw(); | |||||
| 506 | 503 | |||||||
| HITCBC | 507 | 159 | auto const& md = m.metadata(); | 504 | 159 | auto const& md = m.metadata(); | ||
| HITCBC | 508 | 159 | needs_exp100_continue_ = md.expect.is_100_continue; | 505 | 159 | needs_exp100_continue_ = md.expect.is_100_continue; | ||
| 509 | 506 | |||||||
| 510 | // Transfer-Encoding | 507 | // Transfer-Encoding | |||||
| HITCBC | 511 | 159 | is_chunked_ = md.transfer_encoding.is_chunked; | 508 | 159 | is_chunked_ = md.transfer_encoding.is_chunked; | ||
| 512 | 509 | |||||||
| 513 | // Content-Encoding | 510 | // Content-Encoding | |||||
| HITCBC | 514 | 159 | switch (md.content_encoding.coding) | 511 | 159 | switch (md.content_encoding.coding) | ||
| 515 | { | 512 | { | |||||
| MISUBC | 516 | ✗ | case content_coding::deflate: | 513 | ✗ | case content_coding::deflate: | ||
| MISUBC | 517 | ✗ | if(!cfg_->apply_deflate_encoder) | 514 | ✗ | if(!cfg_->apply_deflate_encoder) | ||
| MISUBC | 518 | ✗ | goto no_filter; | 515 | ✗ | goto no_filter; | ||
| MISUBC | 519 | ✗ | if(auto* svc = capy::get_system_context().find_service<http::zlib::deflate_service>()) | 516 | ✗ | if(auto* svc = capy::get_system_context().find_service<http::zlib::deflate_service>()) | ||
| 520 | { | 517 | { | |||||
| MISUBC | 521 | ✗ | filter_.reset(new zlib_filter( | 518 | ✗ | filter_.reset(new zlib_filter( | ||
| 522 | *svc, | 519 | *svc, | |||||
| MISUBC | 523 | ✗ | cfg_->zlib_comp_level, | 520 | ✗ | cfg_->zlib_comp_level, | ||
| MISUBC | 524 | ✗ | cfg_->zlib_window_bits, | 521 | ✗ | cfg_->zlib_window_bits, | ||
| MISUBC | 525 | ✗ | cfg_->zlib_mem_level)); | 522 | ✗ | cfg_->zlib_mem_level)); | ||
| MISUBC | 526 | ✗ | filter_done_ = false; | 523 | ✗ | filter_done_ = false; | ||
| 527 | } | 524 | } | |||||
| MISUBC | 528 | ✗ | break; | 525 | ✗ | break; | ||
| 529 | 526 | |||||||
| MISUBC | 530 | ✗ | case content_coding::gzip: | 527 | ✗ | case content_coding::gzip: | ||
| MISUBC | 531 | ✗ | if(!cfg_->apply_gzip_encoder) | 528 | ✗ | if(!cfg_->apply_gzip_encoder) | ||
| MISUBC | 532 | ✗ | goto no_filter; | 529 | ✗ | goto no_filter; | ||
| MISUBC | 533 | ✗ | if(auto* svc = capy::get_system_context().find_service<http::zlib::deflate_service>()) | 530 | ✗ | if(auto* svc = capy::get_system_context().find_service<http::zlib::deflate_service>()) | ||
| 534 | { | 531 | { | |||||
| MISUBC | 535 | ✗ | filter_.reset(new zlib_filter( | 532 | ✗ | filter_.reset(new zlib_filter( | ||
| 536 | *svc, | 533 | *svc, | |||||
| MISUBC | 537 | ✗ | cfg_->zlib_comp_level, | 534 | ✗ | cfg_->zlib_comp_level, | ||
| MISUBC | 538 | ✗ | cfg_->zlib_window_bits + 16, | 535 | ✗ | cfg_->zlib_window_bits + 16, | ||
| MISUBC | 539 | ✗ | cfg_->zlib_mem_level)); | 536 | ✗ | cfg_->zlib_mem_level)); | ||
| MISUBC | 540 | ✗ | filter_done_ = false; | 537 | ✗ | filter_done_ = false; | ||
| 541 | } | 538 | } | |||||
| MISUBC | 542 | ✗ | break; | 539 | ✗ | break; | ||
| 543 | 540 | |||||||
| MISUBC | 544 | ✗ | case content_coding::br: | 541 | ✗ | case content_coding::br: | ||
| MISUBC | 545 | ✗ | if(!cfg_->apply_brotli_encoder) | 542 | ✗ | if(!cfg_->apply_brotli_encoder) | ||
| MISUBC | 546 | ✗ | goto no_filter; | 543 | ✗ | goto no_filter; | ||
| MISUBC | 547 | ✗ | if(auto* svc = capy::get_system_context().find_service<http::brotli::encode_service>()) | 544 | ✗ | if(auto* svc = capy::get_system_context().find_service<http::brotli::encode_service>()) | ||
| 548 | { | 545 | { | |||||
| MISUBC | 549 | ✗ | filter_.reset(new brotli_filter( | 546 | ✗ | filter_.reset(new brotli_filter( | ||
| 550 | *svc, | 547 | *svc, | |||||
| MISUBC | 551 | ✗ | cfg_->brotli_comp_quality, | 548 | ✗ | cfg_->brotli_comp_quality, | ||
| MISUBC | 552 | ✗ | cfg_->brotli_comp_window)); | 549 | ✗ | cfg_->brotli_comp_window)); | ||
| MISUBC | 553 | ✗ | filter_done_ = false; | 550 | ✗ | filter_done_ = false; | ||
| 554 | } | 551 | } | |||||
| MISUBC | 555 | ✗ | break; | 552 | ✗ | break; | ||
| 556 | 553 | |||||||
| MISUBC | 557 | ✗ | no_filter: | 554 | ✗ | no_filter: | ||
| HITCBC | 558 | 159 | default: | 555 | 159 | default: | ||
| HITCBC | 559 | 159 | filter_.reset(); | 556 | 159 | filter_.reset(); | ||
| HITCBC | 560 | 159 | break; | 557 | 159 | break; | ||
| 561 | } | 558 | } | |||||
| HITCBC | 562 | 159 | } | 559 | 159 | } | ||
| 563 | 560 | |||||||
| 564 | void | 561 | void | |||||
| HITCBC | 565 | 6 | start_empty( | 562 | 6 | start_empty( | ||
| 566 | message_base const& m) | 563 | message_base const& m) | |||||
| 567 | { | 564 | { | |||||
| HITCBC | 568 | 6 | start_init(m); | 565 | 6 | start_init(m); | ||
| HITCBC | 569 | 6 | style_ = style::empty; | 566 | 6 | style_ = style::empty; | ||
| 570 | 567 | |||||||
| HITCBC | 571 | 6 | prepped_ = make_array( | 568 | 6 | prepped_ = make_array( | ||
| 572 | 1 + // header | 569 | 1 + // header | |||||
| 573 | 2); // out buffer pairs | 570 | 2); // out buffer pairs | |||||
| 574 | 571 | |||||||
| HITCBC | 575 | 6 | out_init(); | 572 | 6 | out_init(); | ||
| 576 | 573 | |||||||
| HITCBC | 577 | 6 | if(!filter_) | 574 | 6 | if(!filter_) | ||
| HITCBC | 578 | 6 | out_finish(); | 575 | 6 | out_finish(); | ||
| 579 | 576 | |||||||
| HITCBC | 580 | 6 | prepped_.append({ m.h_.cbuf, m.h_.size }); | 577 | 6 | prepped_.append({ m.h_.cbuf, m.h_.size }); | ||
| HITCBC | 581 | 6 | more_input_ = false; | 578 | 6 | more_input_ = false; | ||
| HITCBC | 582 | 6 | } | 579 | 6 | } | ||
| 583 | 580 | |||||||
| 584 | void | 581 | void | |||||
| HITCBC | 585 | 78 | start_stream(message_base const& m) | 582 | 78 | start_stream(message_base const& m) | ||
| 586 | { | 583 | { | |||||
| HITCBC | 587 | 78 | start_init(m); | 584 | 78 | start_init(m); | ||
| HITCBC | 588 | 78 | style_ = style::stream; | 585 | 78 | style_ = style::stream; | ||
| 589 | 586 | |||||||
| HITCBC | 590 | 78 | prepped_ = make_array( | 587 | 78 | prepped_ = make_array( | ||
| 591 | 1 + // header | 588 | 1 + // header | |||||
| 592 | 2); // out buffer pairs | 589 | 2); // out buffer pairs | |||||
| 593 | 590 | |||||||
| HITCBC | 594 | 78 | if(filter_) | 591 | 78 | if(filter_) | ||
| 595 | { | 592 | { | |||||
| 596 | // TODO: smarter buffer distribution | 593 | // TODO: smarter buffer distribution | |||||
| MISUBC | 597 | ✗ | auto const n = (ws_.size() - 1) / 2; | 594 | ✗ | auto const n = (ws_.size() - 1) / 2; | ||
| MISUBC | 598 | ✗ | in_ = { ws_.reserve_front(n), n }; | 595 | ✗ | in_ = { ws_.reserve_front(n), n }; | ||
| 599 | } | 596 | } | |||||
| 600 | 597 | |||||||
| HITCBC | 601 | 78 | out_init(); | 598 | 78 | out_init(); | ||
| 602 | 599 | |||||||
| HITCBC | 603 | 78 | prepped_.append({ m.h_.cbuf, m.h_.size }); | 600 | 78 | prepped_.append({ m.h_.cbuf, m.h_.size }); | ||
| HITCBC | 604 | 78 | more_input_ = true; | 601 | 78 | more_input_ = true; | ||
| HITCBC | 605 | 78 | } | 602 | 78 | } | ||
| 606 | 603 | |||||||
| 607 | // Like start_stream but without in_ allocation. | 604 | // Like start_stream but without in_ allocation. | |||||
| 608 | // Entire workspace is used for output buffering. | 605 | // Entire workspace is used for output buffering. | |||||
| 609 | void | 606 | void | |||||
| HITCBC | 610 | 75 | start_buffers_direct(message_base const& m) | 607 | 75 | start_buffers_direct(message_base const& m) | ||
| 611 | { | 608 | { | |||||
| HITCBC | 612 | 75 | start_init(m); | 609 | 75 | start_init(m); | ||
| HITCBC | 613 | 75 | style_ = style::stream; | 610 | 75 | style_ = style::stream; | ||
| 614 | 611 | |||||||
| HITCBC | 615 | 75 | prepped_ = make_array( | 612 | 75 | prepped_ = make_array( | ||
| 616 | 1 + // header | 613 | 1 + // header | |||||
| 617 | 2); // out buffer pairs | 614 | 2); // out buffer pairs | |||||
| 618 | 615 | |||||||
| HITCBC | 619 | 75 | out_init(); | 616 | 75 | out_init(); | ||
| 620 | 617 | |||||||
| HITCBC | 621 | 75 | prepped_.append({ m.h_.cbuf, m.h_.size }); | 618 | 75 | prepped_.append({ m.h_.cbuf, m.h_.size }); | ||
| HITCBC | 622 | 75 | more_input_ = true; | 619 | 75 | more_input_ = true; | ||
| HITCBC | 623 | 75 | } | 620 | 75 | } | ||
| 624 | 621 | |||||||
| 625 | std::size_t | 622 | std::size_t | |||||
| HITCBC | 626 | 182 | stream_capacity() const | 623 | 182 | stream_capacity() const | ||
| 627 | { | 624 | { | |||||
| HITCBC | 628 | 182 | if(filter_) | 625 | 182 | if(filter_) | ||
| MISUBC | 629 | ✗ | return in_.capacity(); | 626 | ✗ | return in_.capacity(); | ||
| HITCBC | 630 | 182 | return out_capacity(); | 627 | 182 | return out_capacity(); | ||
| 631 | } | 628 | } | |||||
| 632 | 629 | |||||||
| 633 | std::array<capy::mutable_buffer, 2> | 630 | std::array<capy::mutable_buffer, 2> | |||||
| HITCBC | 634 | 129 | stream_prepare() | 631 | 129 | stream_prepare() | ||
| 635 | { | 632 | { | |||||
| HITCBC | 636 | 129 | if(state_ == state::start) | 633 | 129 | if(state_ == state::start) | ||
| 637 | { | 634 | { | |||||
| MISUBC | 638 | ✗ | if(!msg_) | 635 | ✗ | if(!msg_) | ||
| MISUBC | 639 | ✗ | detail::throw_logic_error(); | 636 | ✗ | detail::throw_logic_error(); | ||
| MISUBC | 640 | ✗ | start_stream(*msg_); | 637 | ✗ | start_stream(*msg_); | ||
| 641 | } | 638 | } | |||||
| HITCBC | 642 | 129 | if(filter_) | 639 | 129 | if(filter_) | ||
| MISUBC | 643 | ✗ | return in_.prepare(in_.capacity()); | 640 | ✗ | return in_.prepare(in_.capacity()); | ||
| HITCBC | 644 | 129 | return out_prepare(); | 641 | 129 | return out_prepare(); | ||
| 645 | } | 642 | } | |||||
| 646 | 643 | |||||||
| 647 | void | 644 | void | |||||
| HITCBC | 648 | 165 | stream_commit(std::size_t n) | 645 | 165 | stream_commit(std::size_t n) | ||
| 649 | { | 646 | { | |||||
| HITCBC | 650 | 165 | if(n > stream_capacity()) | 647 | 165 | if(n > stream_capacity()) | ||
| HITCBC | 651 | 1 | detail::throw_invalid_argument(); | 648 | 1 | detail::throw_invalid_argument(); | ||
| 652 | 649 | |||||||
| HITCBC | 653 | 164 | if(filter_) | 650 | 164 | if(filter_) | ||
| MISUBC | 654 | ✗ | return in_.commit(n); | 651 | ✗ | return in_.commit(n); | ||
| 655 | 652 | |||||||
| HITCBC | 656 | 164 | out_commit(n); | 653 | 164 | out_commit(n); | ||
| 657 | } | 654 | } | |||||
| 658 | 655 | |||||||
| 659 | void | 656 | void | |||||
| HITCBC | 660 | 75 | stream_close() noexcept | 657 | 75 | stream_close() noexcept | ||
| 661 | { | 658 | { | |||||
| HITCBC | 662 | 75 | if(!filter_) | 659 | 75 | if(!filter_) | ||
| HITCBC | 663 | 75 | out_finish(); | 660 | 75 | out_finish(); | ||
| 664 | 661 | |||||||
| HITCBC | 665 | 75 | more_input_ = false; | 662 | 75 | more_input_ = false; | ||
| HITCBC | 666 | 75 | } | 663 | 75 | } | ||
| 667 | 664 | |||||||
| 668 | bool | 665 | bool | |||||
| HITCBC | 669 | 464 | is_done() const noexcept | 666 | 464 | is_done() const noexcept | ||
| 670 | { | 667 | { | |||||
| HITCBC | 671 | 464 | return state_ == state::start; | 668 | 464 | return state_ == state::start; | ||
| 672 | } | 669 | } | |||||
| 673 | 670 | |||||||
| 674 | bool | 671 | bool | |||||
| HITCBC | 675 | 249 | is_start() const noexcept | 672 | 249 | is_start() const noexcept | ||
| 676 | { | 673 | { | |||||
| HITCBC | 677 | 249 | return state_ == state::start; | 674 | 249 | return state_ == state::start; | ||
| 678 | } | 675 | } | |||||
| 679 | 676 | |||||||
| 680 | detail::workspace& | 677 | detail::workspace& | |||||
| MISUBC | 681 | ✗ | ws() noexcept | 678 | ✗ | ws() noexcept | ||
| 682 | { | 679 | { | |||||
| MISUBC | 683 | ✗ | return ws_; | 680 | ✗ | return ws_; | ||
| 684 | } | 681 | } | |||||
| 685 | 682 | |||||||
| 686 | private: | 683 | private: | |||||
| 687 | bool | 684 | bool | |||||
| HITCBC | 688 | 2384 | is_header_done() const noexcept | 685 | 2384 | is_header_done() const noexcept | ||
| 689 | { | 686 | { | |||||
| HITCBC | 690 | 2384 | return state_ == state::body; | 687 | 2384 | return state_ == state::body; | ||
| 691 | } | 688 | } | |||||
| 692 | 689 | |||||||
| 693 | detail::array_of_const_buffers | 690 | detail::array_of_const_buffers | |||||
| HITCBC | 694 | 159 | make_array(std::size_t n) | 691 | 159 | make_array(std::size_t n) | ||
| 695 | { | 692 | { | |||||
| HITCBC | 696 | 159 | BOOST_ASSERT(n <= std::uint16_t(-1)); | 693 | 159 | BOOST_ASSERT(n <= std::uint16_t(-1)); | ||
| 697 | 694 | |||||||
| 698 | return { | 695 | return { | |||||
| HITCBC | 699 | 159 | ws_.push_array(n, | 696 | 159 | ws_.push_array(n, | ||
| MISUBC | 700 | ✗ | capy::const_buffer{}), | 697 | ✗ | capy::const_buffer{}), | ||
| HITCBC | 701 | 159 | static_cast<std::uint16_t>(n) }; | 698 | 159 | static_cast<std::uint16_t>(n) }; | ||
| 702 | } | 699 | } | |||||
| 703 | 700 | |||||||
| 704 | void | 701 | void | |||||
| HITCBC | 705 | 159 | out_init() | 702 | 159 | out_init() | ||
| 706 | { | 703 | { | |||||
| 707 | // use all the remaining buffer | 704 | // use all the remaining buffer | |||||
| HITCBC | 708 | 159 | auto const n = ws_.size() - 1; | 705 | 159 | auto const n = ws_.size() - 1; | ||
| HITCBC | 709 | 159 | out_ = { ws_.reserve_front(n), n }; | 706 | 159 | out_ = { ws_.reserve_front(n), n }; | ||
| HITCBC | 710 | 159 | chunk_header_len_ = | 707 | 159 | chunk_header_len_ = | ||
| HITCBC | 711 | 159 | chunk_header_len(out_.capacity()); | 708 | 159 | chunk_header_len(out_.capacity()); | ||
| HITCBC | 712 | 159 | if(out_capacity() == 0) | 709 | 159 | if(out_capacity() == 0) | ||
| MISUBC | 713 | ✗ | detail::throw_length_error(); | 710 | ✗ | detail::throw_length_error(); | ||
| HITCBC | 714 | 159 | } | 711 | 159 | } | ||
| 715 | 712 | |||||||
| 716 | std::array<capy::mutable_buffer, 2> | 713 | std::array<capy::mutable_buffer, 2> | |||||
| HITCBC | 717 | 129 | out_prepare() noexcept | 714 | 129 | out_prepare() noexcept | ||
| 718 | { | 715 | { | |||||
| HITCBC | 719 | 129 | auto mbp = out_.prepare(out_.capacity()); | 716 | 129 | auto mbp = out_.prepare(out_.capacity()); | ||
| HITCBC | 720 | 129 | if(is_chunked_) | 717 | 129 | if(is_chunked_) | ||
| 721 | { | 718 | { | |||||
| HITCBC | 722 | 69 | trim_prefix_pair( | 719 | 69 | trim_prefix_pair( | ||
| HITCBC | 723 | 69 | mbp, chunk_header_len_); | 720 | 69 | mbp, chunk_header_len_); | ||
| HITCBC | 724 | 69 | trim_suffix_pair( | 721 | 69 | trim_suffix_pair( | ||
| 725 | mbp, crlf_and_final_chunk.size()); | 722 | mbp, crlf_and_final_chunk.size()); | |||||
| 726 | } | 723 | } | |||||
| HITCBC | 727 | 129 | return mbp; | 724 | 129 | return mbp; | ||
| 728 | } | 725 | } | |||||
| 729 | 726 | |||||||
| 730 | void | 727 | void | |||||
| HITCBC | 731 | 164 | out_commit( | 728 | 164 | out_commit( | ||
| 732 | std::size_t n) noexcept | 729 | std::size_t n) noexcept | |||||
| 733 | { | 730 | { | |||||
| HITCBC | 734 | 164 | if(is_chunked_) | 731 | 164 | if(is_chunked_) | ||
| 735 | { | 732 | { | |||||
| HITCBC | 736 | 87 | if(n == 0) | 733 | 87 | if(n == 0) | ||
| HITCBC | 737 | 19 | return; | 734 | 19 | return; | ||
| 738 | 735 | |||||||
| HITCBC | 739 | 68 | write_chunk_header(out_.prepare(chunk_header_len_), n); | 736 | 68 | write_chunk_header(out_.prepare(chunk_header_len_), n); | ||
| HITCBC | 740 | 68 | out_.commit(chunk_header_len_); | 737 | 68 | out_.commit(chunk_header_len_); | ||
| 741 | 738 | |||||||
| HITCBC | 742 | 68 | out_.prepare(n); | 739 | 68 | out_.prepare(n); | ||
| HITCBC | 743 | 68 | out_.commit(n); | 740 | 68 | out_.commit(n); | ||
| 744 | 741 | |||||||
| HITCBC | 745 | 68 | capy::buffer_copy(out_.prepare(crlf.size()), crlf); | 742 | 68 | capy::buffer_copy(out_.prepare(crlf.size()), crlf); | ||
| HITCBC | 746 | 68 | out_.commit(crlf.size()); | 743 | 68 | out_.commit(crlf.size()); | ||
| 747 | } | 744 | } | |||||
| 748 | else | 745 | else | |||||
| 749 | { | 746 | { | |||||
| HITCBC | 750 | 77 | out_.commit(n); | 747 | 77 | out_.commit(n); | ||
| 751 | } | 748 | } | |||||
| 752 | } | 749 | } | |||||
| 753 | 750 | |||||||
| 754 | std::size_t | 751 | std::size_t | |||||
| HITCBC | 755 | 341 | out_capacity() const noexcept | 752 | 341 | out_capacity() const noexcept | ||
| 756 | { | 753 | { | |||||
| HITCBC | 757 | 341 | if(is_chunked_) | 754 | 341 | if(is_chunked_) | ||
| 758 | { | 755 | { | |||||
| HITCBC | 759 | 174 | auto const overhead = chunk_header_len_ + | 756 | 174 | auto const overhead = chunk_header_len_ + | ||
| HITCBC | 760 | 174 | crlf_and_final_chunk.size(); | 757 | 174 | crlf_and_final_chunk.size(); | ||
| HITCBC | 761 | 174 | if(out_.capacity() < overhead) | 758 | 174 | if(out_.capacity() < overhead) | ||
| HITCBC | 762 | 1 | return 0; | 759 | 1 | return 0; | ||
| HITCBC | 763 | 173 | return out_.capacity() - overhead; | 760 | 173 | return out_.capacity() - overhead; | ||
| 764 | } | 761 | } | |||||
| HITCBC | 765 | 167 | return out_.capacity(); | 762 | 167 | return out_.capacity(); | ||
| 766 | } | 763 | } | |||||
| 767 | 764 | |||||||
| 768 | void | 765 | void | |||||
| HITCBC | 769 | 81 | out_finish() noexcept | 766 | 81 | out_finish() noexcept | ||
| 770 | { | 767 | { | |||||
| HITCBC | 771 | 81 | if(is_chunked_) | 768 | 81 | if(is_chunked_) | ||
| 772 | { | 769 | { | |||||
| HITCBC | 773 | 41 | capy::buffer_copy( | 770 | 41 | capy::buffer_copy( | ||
| HITCBC | 774 | 41 | out_.prepare(final_chunk.size()), final_chunk); | 771 | 41 | out_.prepare(final_chunk.size()), final_chunk); | ||
| HITCBC | 775 | 41 | out_.commit(final_chunk.size()); | 772 | 41 | out_.commit(final_chunk.size()); | ||
| 776 | } | 773 | } | |||||
| HITCBC | 777 | 81 | } | 774 | 81 | } | ||
| 778 | }; | 775 | }; | |||||
| 779 | 776 | |||||||
| 780 | //------------------------------------------------ | 777 | //------------------------------------------------ | |||||
| 781 | 778 | |||||||
| HITCBC | 782 | 163 | serializer:: | 779 | 163 | serializer:: | ||
| 783 | ~serializer() | 780 | ~serializer() | |||||
| 784 | { | 781 | { | |||||
| HITCBC | 785 | 163 | delete impl_; | 782 | 163 | delete impl_; | ||
| HITCBC | 786 | 163 | } | 783 | 163 | } | ||
| 787 | 784 | |||||||
| HITCBC | 788 | 1 | serializer:: | 785 | 1 | serializer:: | ||
| HITCBC | 789 | 1 | serializer(serializer&& other) noexcept | 786 | 1 | serializer(serializer&& other) noexcept | ||
| HITCBC | 790 | 1 | : impl_(other.impl_) | 787 | 1 | : impl_(other.impl_) | ||
| 791 | { | 788 | { | |||||
| HITCBC | 792 | 1 | other.impl_ = nullptr; | 789 | 1 | other.impl_ = nullptr; | ||
| HITCBC | 793 | 1 | } | 790 | 1 | } | ||
| 794 | 791 | |||||||
| 795 | serializer& | 792 | serializer& | |||||
| HITCBC | 796 | 2 | serializer:: | 793 | 2 | serializer:: | ||
| 797 | operator=(serializer&& other) noexcept | 794 | operator=(serializer&& other) noexcept | |||||
| 798 | { | 795 | { | |||||
| HITCBC | 799 | 2 | if(this != &other) | 796 | 2 | if(this != &other) | ||
| 800 | { | 797 | { | |||||
| HITCBC | 801 | 2 | delete impl_; | 798 | 2 | delete impl_; | ||
| HITCBC | 802 | 2 | impl_ = other.impl_; | 799 | 2 | impl_ = other.impl_; | ||
| HITCBC | 803 | 2 | other.impl_ = nullptr; | 800 | 2 | other.impl_ = nullptr; | ||
| 804 | } | 801 | } | |||||
| HITCBC | 805 | 2 | return *this; | 802 | 2 | return *this; | ||
| 806 | } | 803 | } | |||||
| 807 | 804 | |||||||
| HITCBC | 808 | 158 | serializer:: | 805 | 158 | serializer:: | ||
| 809 | serializer( | 806 | serializer( | |||||
| HITCBC | 810 | 158 | std::shared_ptr<serializer_config_impl const> cfg) | 807 | 158 | std::shared_ptr<serializer_config_impl const> cfg) | ||
| HITCBC | 811 | 158 | : impl_(new impl(std::move(cfg))) | 808 | 158 | : impl_(new impl(std::move(cfg))) | ||
| 812 | { | 809 | { | |||||
| HITCBC | 813 | 158 | } | 810 | 158 | } | ||
| 814 | 811 | |||||||
| 815 | void | 812 | void | |||||
| HITCBC | 816 | 4 | serializer:: | 813 | 4 | serializer:: | ||
| 817 | reset() noexcept | 814 | reset() noexcept | |||||
| 818 | { | 815 | { | |||||
| HITCBC | 819 | 4 | BOOST_ASSERT(impl_); | 816 | 4 | BOOST_ASSERT(impl_); | ||
| HITCBC | 820 | 4 | impl_->reset(); | 817 | 4 | impl_->reset(); | ||
| HITCBC | 821 | 4 | } | 818 | 4 | } | ||
| 822 | 819 | |||||||
| 823 | void | 820 | void | |||||
| HITCBC | 824 | 159 | serializer:: | 821 | 159 | serializer:: | ||
| 825 | set_message(message_base const& m) noexcept | 822 | set_message(message_base const& m) noexcept | |||||
| 826 | { | 823 | { | |||||
| HITCBC | 827 | 159 | BOOST_ASSERT(impl_); | 824 | 159 | BOOST_ASSERT(impl_); | ||
| HITCBC | 828 | 159 | impl_->msg_ = &m; | 825 | 159 | impl_->msg_ = &m; | ||
| HITCBC | 829 | 159 | } | 826 | 159 | } | ||
| 830 | 827 | |||||||
| 831 | void | 828 | void | |||||
| HITCBC | 832 | 6 | serializer:: | 829 | 6 | serializer:: | ||
| 833 | start() | 830 | start() | |||||
| 834 | { | 831 | { | |||||
| HITCBC | 835 | 6 | if(!impl_ || !impl_->msg_) | 832 | 6 | if(!impl_ || !impl_->msg_) | ||
| MISUBC | 836 | ✗ | detail::throw_logic_error(); | 833 | ✗ | detail::throw_logic_error(); | ||
| HITCBC | 837 | 6 | impl_->start_empty(*impl_->msg_); | 834 | 6 | impl_->start_empty(*impl_->msg_); | ||
| HITCBC | 838 | 6 | } | 835 | 6 | } | ||
| 839 | 836 | |||||||
| 840 | void | 837 | void | |||||
| MISUBC | 841 | ✗ | serializer:: | 838 | ✗ | serializer:: | ||
| 842 | start_stream() | 839 | start_stream() | |||||
| 843 | { | 840 | { | |||||
| MISUBC | 844 | ✗ | if(!impl_ || !impl_->msg_) | 841 | ✗ | if(!impl_ || !impl_->msg_) | ||
| MISUBC | 845 | ✗ | detail::throw_logic_error(); | 842 | ✗ | detail::throw_logic_error(); | ||
| MISUBC | 846 | ✗ | impl_->start_stream(*impl_->msg_); | 843 | ✗ | impl_->start_stream(*impl_->msg_); | ||
| MISUBC | 847 | ✗ | } | 844 | ✗ | } | ||
| 848 | 845 | |||||||
| 849 | void | 846 | void | |||||
| HITCBC | 850 | 78 | serializer:: | 847 | 78 | serializer:: | ||
| 851 | start_writes() | 848 | start_writes() | |||||
| 852 | { | 849 | { | |||||
| HITCBC | 853 | 78 | if(!impl_ || !impl_->msg_) | 850 | 78 | if(!impl_ || !impl_->msg_) | ||
| MISUBC | 854 | ✗ | detail::throw_logic_error(); | 851 | ✗ | detail::throw_logic_error(); | ||
| HITCBC | 855 | 78 | impl_->start_stream(*impl_->msg_); | 852 | 78 | impl_->start_stream(*impl_->msg_); | ||
| HITCBC | 856 | 78 | } | 853 | 78 | } | ||
| 857 | 854 | |||||||
| 858 | void | 855 | void | |||||
| HITCBC | 859 | 75 | serializer:: | 856 | 75 | serializer:: | ||
| 860 | start_buffers() | 857 | start_buffers() | |||||
| 861 | { | 858 | { | |||||
| HITCBC | 862 | 75 | if(!impl_ || !impl_->msg_) | 859 | 75 | if(!impl_ || !impl_->msg_) | ||
| MISUBC | 863 | ✗ | detail::throw_logic_error(); | 860 | ✗ | detail::throw_logic_error(); | ||
| HITCBC | 864 | 75 | impl_->start_buffers_direct(*impl_->msg_); | 861 | 75 | impl_->start_buffers_direct(*impl_->msg_); | ||
| HITCBC | 865 | 75 | } | 862 | 75 | } | ||
| 866 | 863 | |||||||
| 867 | auto | 864 | auto | |||||
| HITCBC | 868 | 389 | serializer:: | 865 | 389 | serializer:: | ||
| 869 | prepare() -> | 866 | prepare() -> | |||||
| 870 | system::result<const_buffers_type> | 867 | system::result<const_buffers_type> | |||||
| 871 | { | 868 | { | |||||
| HITCBC | 872 | 389 | BOOST_ASSERT(impl_); | 869 | 389 | BOOST_ASSERT(impl_); | ||
| HITCBC | 873 | 389 | return impl_->prepare(); | 870 | 389 | return impl_->prepare(); | ||
| 874 | } | 871 | } | |||||
| 875 | 872 | |||||||
| 876 | void | 873 | void | |||||
| HITCBC | 877 | 1902 | serializer:: | 874 | 1902 | serializer:: | ||
| 878 | consume(std::size_t n) | 875 | consume(std::size_t n) | |||||
| 879 | { | 876 | { | |||||
| HITCBC | 880 | 1902 | BOOST_ASSERT(impl_); | 877 | 1902 | BOOST_ASSERT(impl_); | ||
| HITCBC | 881 | 1902 | impl_->consume(n); | 878 | 1902 | impl_->consume(n); | ||
| HITCBC | 882 | 1901 | } | 879 | 1901 | } | ||
| 883 | 880 | |||||||
| 884 | bool | 881 | bool | |||||
| HITCBC | 885 | 464 | serializer:: | 882 | 464 | serializer:: | ||
| 886 | is_done() const noexcept | 883 | is_done() const noexcept | |||||
| 887 | { | 884 | { | |||||
| HITCBC | 888 | 464 | BOOST_ASSERT(impl_); | 885 | 464 | BOOST_ASSERT(impl_); | ||
| HITCBC | 889 | 464 | return impl_->is_done(); | 886 | 464 | return impl_->is_done(); | ||
| 890 | } | 887 | } | |||||
| 891 | 888 | |||||||
| 892 | bool | 889 | bool | |||||
| HITCBC | 893 | 249 | serializer:: | 890 | 249 | serializer:: | ||
| 894 | is_start() const noexcept | 891 | is_start() const noexcept | |||||
| 895 | { | 892 | { | |||||
| HITCBC | 896 | 249 | BOOST_ASSERT(impl_); | 893 | 249 | BOOST_ASSERT(impl_); | ||
| HITCBC | 897 | 249 | return impl_->is_start(); | 894 | 249 | return impl_->is_start(); | ||
| 898 | } | 895 | } | |||||
| 899 | 896 | |||||||
| 900 | //------------------------------------------------ | 897 | //------------------------------------------------ | |||||
| 901 | 898 | |||||||
| 902 | detail::workspace& | 899 | detail::workspace& | |||||
| MISUBC | 903 | ✗ | serializer:: | 900 | ✗ | serializer:: | ||
| 904 | ws() | 901 | ws() | |||||
| 905 | { | 902 | { | |||||
| MISUBC | 906 | ✗ | BOOST_ASSERT(impl_); | 903 | ✗ | BOOST_ASSERT(impl_); | ||
| MISUBC | 907 | ✗ | return impl_->ws(); | 904 | ✗ | return impl_->ws(); | ||
| 908 | } | 905 | } | |||||
| 909 | 906 | |||||||
| 910 | //------------------------------------------------ | 907 | //------------------------------------------------ | |||||
| 911 | 908 | |||||||
| 912 | std::size_t | 909 | std::size_t | |||||
| HITCBC | 913 | 17 | serializer:: | 910 | 17 | serializer:: | ||
| 914 | stream_capacity() const | 911 | stream_capacity() const | |||||
| 915 | { | 912 | { | |||||
| HITCBC | 916 | 17 | BOOST_ASSERT(impl_); | 913 | 17 | BOOST_ASSERT(impl_); | ||
| HITCBC | 917 | 17 | return impl_->stream_capacity(); | 914 | 17 | return impl_->stream_capacity(); | ||
| 918 | } | 915 | } | |||||
| 919 | 916 | |||||||
| 920 | auto | 917 | auto | |||||
| HITCBC | 921 | 129 | serializer:: | 918 | 129 | serializer:: | ||
| 922 | stream_prepare() -> | 919 | stream_prepare() -> | |||||
| 923 | mutable_buffers_type | 920 | mutable_buffers_type | |||||
| 924 | { | 921 | { | |||||
| HITCBC | 925 | 129 | BOOST_ASSERT(impl_); | 922 | 129 | BOOST_ASSERT(impl_); | ||
| HITCBC | 926 | 129 | return impl_->stream_prepare(); | 923 | 129 | return impl_->stream_prepare(); | ||
| 927 | } | 924 | } | |||||
| 928 | 925 | |||||||
| 929 | void | 926 | void | |||||
| HITCBC | 930 | 165 | serializer:: | 927 | 165 | serializer:: | ||
| 931 | stream_commit(std::size_t n) | 928 | stream_commit(std::size_t n) | |||||
| 932 | { | 929 | { | |||||
| HITCBC | 933 | 165 | BOOST_ASSERT(impl_); | 930 | 165 | BOOST_ASSERT(impl_); | ||
| HITCBC | 934 | 165 | impl_->stream_commit(n); | 931 | 165 | impl_->stream_commit(n); | ||
| HITCBC | 935 | 164 | } | 932 | 164 | } | ||
| 936 | 933 | |||||||
| 937 | void | 934 | void | |||||
| HITCBC | 938 | 75 | serializer:: | 935 | 75 | serializer:: | ||
| 939 | stream_close() noexcept | 936 | stream_close() noexcept | |||||
| 940 | { | 937 | { | |||||
| HITCBC | 941 | 75 | BOOST_ASSERT(impl_); | 938 | 75 | BOOST_ASSERT(impl_); | ||
| HITCBC | 942 | 75 | impl_->stream_close(); | 939 | 75 | impl_->stream_close(); | ||
| HITCBC | 943 | 75 | } | 940 | 75 | } | ||
| 944 | 941 | |||||||
| 945 | } // http | 942 | } // http | |||||
| 946 | } // boost | 943 | } // boost | |||||