GCC Code Coverage Report


Directory: libs/http_proto/
File: src/detail/zlib_filter_base.hpp
Date: 2025-09-21 18:08:15
Exec Total Coverage
Lines: 11 14 78.6%
Functions: 3 4 75.0%
Branches: 1 2 50.0%

Line Branch Exec Source
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_ZLIB_FILTER_BASE_HPP
12 #define BOOST_HTTP_PROTO_DETAIL_ZLIB_FILTER_BASE_HPP
13
14 #include <boost/http_proto/detail/workspace.hpp>
15
16 #include "src/detail/filter.hpp"
17
18 #include <boost/rts/zlib/stream.hpp>
19 #include <boost/rts/zlib/flush.hpp>
20
21 namespace boost {
22 namespace http_proto {
23 namespace detail {
24
25 /** Base class for zlib filters
26 */
27 class zlib_filter_base : public filter
28 {
29 public:
30 124 zlib_filter_base(workspace& w)
31 124 {
32 124 strm_.zalloc = &zalloc;
33 124 strm_.zfree = &zfree;
34 124 strm_.opaque = &w;
35 124 }
36
37 protected:
38 rts::zlib::stream strm_;
39
40 static
41 unsigned int
42 245988 saturate_cast(std::size_t n) noexcept
43 {
44
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 245988 times.
245988 if(n >= std::numeric_limits<unsigned int>::max())
45 return std::numeric_limits<unsigned int>::max();
46 245988 return static_cast<unsigned int>(n);
47 }
48
49 private:
50 static
51 void*
52 368 zalloc(
53 void* opaque,
54 unsigned items,
55 unsigned size) noexcept
56 {
57 return reinterpret_cast<workspace*>(opaque)
58 368 ->try_reserve_front(items * size);
59 }
60
61 static
62 void
63 zfree(
64 void* /* opaque */,
65 void* /* addr */) noexcept
66 {
67 // no-op
68 }
69 };
70
71 } // detail
72 } // http_proto
73 } // boost
74
75 #endif
76