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