LCOV - code coverage report
Current view: top level - libs/http_proto/src/detail/impl/array_of_const_buffers.cpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 97.4 % 38 37
Test Date: 2025-06-18 09:40:26 Functions: 100.0 % 5 5

            Line data    Source code
       1              : //
       2              : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
       3              : // Copyright (c) 2025 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/http_proto
       9              : //
      10              : 
      11              : #include <boost/http_proto/detail/array_of_const_buffers.hpp>
      12              : #include <boost/http_proto/detail/except.hpp>
      13              : 
      14              : #include <boost/buffers/sans_prefix.hpp>
      15              : 
      16              : namespace boost {
      17              : namespace http_proto {
      18              : namespace detail {
      19              : 
      20           99 : array_of_const_buffers::
      21              : array_of_const_buffers(
      22              :     value_type* p,
      23           99 :     std::uint16_t n) noexcept
      24           99 :     : base_(p)
      25           99 :     , cap_(n)
      26           99 :     , pos_(0)
      27           99 :     , size_(n)
      28              : {
      29           99 : }
      30              : 
      31              : void
      32        10863 : array_of_const_buffers::
      33              : consume(std::size_t n)
      34              : {
      35        10863 :     while(size_ > 0)
      36              :     {
      37        10856 :         auto* p = base_ + pos_;
      38        10856 :         if(n < p->size())
      39              :         {
      40         1720 :             *p = buffers::sans_prefix(*p, n);
      41         1720 :             return;
      42              :         }
      43         9136 :         n -= p->size();
      44         9136 :         ++pos_;
      45         9136 :         --size_;
      46         9136 :         if(n == 0)
      47         9136 :             return;
      48              :     }
      49              : 
      50              :     // n exceeded available size
      51            7 :     if(n > 0)
      52            0 :         detail::throw_logic_error();
      53              : }
      54              : 
      55              : void
      56         9012 : array_of_const_buffers::
      57              : reset(std::uint16_t n) noexcept
      58              : {
      59         9012 :     BOOST_ASSERT(n <= cap_);
      60         9012 :     pos_  = 0;
      61         9012 :     size_ = n;
      62         9012 : }
      63              : 
      64              : void
      65            2 : array_of_const_buffers::
      66              : slide_to_front() noexcept
      67              : {
      68            2 :     auto* p = base_ + pos_; // begin
      69            2 :     auto* e = p + size_; // end
      70            2 :     auto* d = base_; // dest
      71           15 :     while(p < e)
      72           13 :         *d++ = *p++;
      73            2 :     pos_ = 0;
      74            2 : }
      75              : 
      76              : void
      77         9037 : array_of_const_buffers::
      78              : append(value_type buf) noexcept
      79              : {
      80         9037 :     BOOST_ASSERT(size_ < cap_);
      81         9037 :     base_[pos_ + size_] = buf;
      82         9037 :     ++size_;
      83         9037 : }
      84              : 
      85              : } // detail
      86              : } // http_proto
      87              : } // boost
        

Generated by: LCOV version 2.1