src/detail/filter.hpp

0.0% Lines (0/3) 0.0% List of functions (0/2)
filter.hpp
f(x) Functions (2)
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2024 Mohammad Nejati
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // Official repository: https://github.com/cppalliance/http
9 //
10
11 #ifndef BOOST_HTTP_DETAIL_FILTER_HPP
12 #define BOOST_HTTP_DETAIL_FILTER_HPP
13
14 #include <boost/capy/buffers.hpp>
15 #include <boost/core/span.hpp>
16 #include <boost/system/error_code.hpp>
17
18 #include <array>
19
20 namespace boost {
21 namespace http {
22 namespace detail {
23
24 /** Base class for all filters
25 */
26 class filter
27 {
28 public:
29 virtual ~filter() = default;
30
31 /** The results of processing the filter.
32 */
33 struct results
34 {
35 /** The error, if any occurred.
36 */
37 system::error_code ec;
38
39 /** The number of bytes produced in the output.
40
41 This may be less than the total number
42 of bytes available for writing in the
43 destination buffers.
44 */
45 std::size_t out_bytes = 0;
46
47 /** The number of bytes consumed from the input.
48
49 This may be less than the total number
50 of bytes available for reading in the
51 source buffers.
52 */
53 std::size_t in_bytes = 0;
54
55 /** True if the output buffer is too
56 small to make progress.
57
58 This can only happen in deflate operation.
59 */
60 bool out_short = false;
61
62 /** True if there will be no more output.
63 */
64 bool finished = false;
65 };
66
67 results
68 process(
69 boost::span<const capy::mutable_buffer> out,
70 std::array<capy::const_buffer, 2> in,
71 bool more);
72
73 protected:
74 virtual
75 std::size_t
76 min_out_buffer() const noexcept
77 {
78 return 0;
79 }
80
81 virtual
82 results
83 do_process(
84 capy::mutable_buffer,
85 capy::const_buffer,
86 bool) noexcept = 0;
87 };
88
89 } // detail
90 } // http
91 } // boost
92
93 #endif
94