Line data 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/buffers
9 : //
10 :
11 : #ifndef BOOST_HTTP_PROTO_DETAIL_FILTER_HPP
12 : #define BOOST_HTTP_PROTO_DETAIL_FILTER_HPP
13 :
14 : #include <boost/http_proto/detail/config.hpp>
15 : #include <boost/buffers/const_buffer.hpp>
16 : #include <boost/buffers/const_buffer_span.hpp>
17 : #include <boost/buffers/mutable_buffer_span.hpp>
18 : #include <boost/buffers/type_traits.hpp>
19 : #include <boost/system/error_code.hpp>
20 : #include <cstddef>
21 :
22 : namespace boost {
23 : namespace http_proto {
24 : namespace detail {
25 :
26 : /** A filter for buffers
27 : */
28 : class BOOST_HTTP_PROTO_DECL
29 : filter
30 : {
31 : template<
32 : class T,
33 : std::size_t N>
34 : class unrolled;
35 :
36 : public:
37 : /** The results of processing the filter.
38 : */
39 : struct results
40 : {
41 : /** The number of bytes produced in the output.
42 :
43 : This may be less than the total number
44 : of bytes available for writing in the
45 : destination buffers.
46 : */
47 : std::size_t out_bytes = 0;
48 :
49 : /** The number of bytes consumed from the input.
50 :
51 : This may be less than the total number
52 : of bytes available for reading in the
53 : source buffers.
54 : */
55 : std::size_t in_bytes = 0;
56 :
57 : /** The error, if any occurred.
58 : */
59 : system::error_code ec;
60 :
61 : /** True if there will be no more output.
62 : */
63 : bool finished = false;
64 : };
65 :
66 : /** Called to process the filter.
67 :
68 : @par Preconditions
69 : @ref init was called once before any
70 : calls to `process`.
71 : */
72 : template<
73 : class MutableBufferSequence,
74 : class ConstBufferSequence>
75 : results
76 83811 : process(
77 : MutableBufferSequence const& out,
78 : ConstBufferSequence const& in,
79 : bool more)
80 : {
81 : static_assert(
82 : buffers::is_mutable_buffer_sequence<
83 : MutableBufferSequence>::value,
84 : "Type requirements not met");
85 :
86 : static_assert(
87 : buffers::is_const_buffer_sequence<
88 : ConstBufferSequence>::value,
89 : "Type requirements not met");
90 :
91 83811 : return process_impl(out, in, more);
92 : }
93 :
94 : #ifdef BOOST_BUFFERS_DOCS
95 : protected:
96 : #else
97 : private:
98 : #endif
99 : /** Derived class override.
100 :
101 : @par Preconditions
102 : @ref init was called once before any
103 : calls to `process`
104 : */
105 : virtual
106 : results
107 : on_process(
108 : buffers::mutable_buffer out,
109 : buffers::const_buffer in,
110 : bool more) = 0;
111 :
112 : private:
113 : results
114 143254 : process_impl(
115 : buffers::mutable_buffer const& out,
116 : buffers::const_buffer const& in,
117 : bool more)
118 : {
119 143254 : return on_process(out, in, more);
120 : }
121 :
122 : template<
123 : class MutableBufferSequence,
124 : class ConstBufferSequence>
125 : results
126 : process_impl(
127 : MutableBufferSequence const& out,
128 : ConstBufferSequence const& in,
129 : bool more);
130 : };
131 :
132 : } // detail
133 : } // http_proto
134 : } // boost
135 :
136 : #include "impl/filter.hpp"
137 :
138 : #endif
|