LCOV - code coverage report
Current view: top level - libs/http/src/detail - zlib_filter_base.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 78.6 % 14 11
Test Date: 2026-01-15 20:43:57 Functions: 75.0 % 4 3

            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_DETAIL_ZLIB_FILTER_BASE_HPP
      12              : #define BOOST_HTTP_DETAIL_ZLIB_FILTER_BASE_HPP
      13              : 
      14              : #include <boost/http/detail/workspace.hpp>
      15              : 
      16              : #include "src/detail/filter.hpp"
      17              : 
      18              : #include <boost/capy/zlib/stream.hpp>
      19              : #include <boost/capy/zlib/flush.hpp>
      20              : 
      21              : namespace boost {
      22              : namespace http {
      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              :     capy::zlib::stream strm_;
      39              : 
      40              :     static
      41              :     unsigned int
      42       245988 :     saturate_cast(std::size_t n) noexcept
      43              :     {
      44       245988 :         if(n >= std::numeric_limits<unsigned int>::max())
      45            0 :             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            0 :     zfree(
      64              :         void* /* opaque */,
      65              :         void* /* addr */) noexcept
      66              :     {
      67              :         // no-op
      68            0 :     }
      69              : };
      70              : 
      71              : } // detail
      72              : } // http
      73              : } // boost
      74              : 
      75              : #endif
        

Generated by: LCOV version 2.3