Line data Source code
1 : //
2 : // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
3 : // Copyright (c) 2024 Christian Mazakas
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_proto
9 : //
10 :
11 : #ifndef BOOST_HTTP_PROTO_SERVICE_ZLIB_SERVICE_HPP
12 : #define BOOST_HTTP_PROTO_SERVICE_ZLIB_SERVICE_HPP
13 :
14 : #include <boost/http_proto/detail/config.hpp>
15 : #include <boost/http_proto/context.hpp>
16 : #include <boost/http_proto/filter.hpp>
17 : #include <boost/http_proto/service/service.hpp>
18 : #include <boost/http_proto/detail/workspace.hpp>
19 :
20 : namespace boost {
21 : namespace http_proto {
22 : namespace zlib {
23 :
24 : struct decoder_config
25 : {
26 : unsigned max_window_bits = 15;
27 : unsigned mem_level = 8;
28 : };
29 :
30 : //------------------------------------------------
31 :
32 : constexpr
33 : inline
34 : std::size_t
35 24 : encoding_size_hint(decoder_config cfg = {}) noexcept
36 : {
37 : // from: https://www.zlib.net/zlib_tech.html
38 : //
39 : // Memory Footprint
40 : //
41 : // zlib's memory footprint can also be specified fairly
42 : // precisely. It is larger for compression than for
43 : // decompression, and the exact requirements depend on
44 : // how the library was compiled.
45 : //
46 : // The memory requirements for compression depend on two
47 : // parameters, windowBits and memLevel:
48 : // deflate memory usage (bytes) = (1 << (windowBits+2)) + (1 << (memLevel+9)) + 6 KB
49 : return
50 24 : (1 << (cfg.max_window_bits + 2)) +
51 24 : (1 << (cfg.mem_level + 9)) +
52 24 : (6 * 1024);
53 : }
54 :
55 : void BOOST_HTTP_PROTO_ZLIB_DECL
56 : install_deflate_encoder(context& ctx);
57 :
58 : } // zlib
59 : } // http_proto
60 : } // boost
61 :
62 : #endif
|