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