LCOV - code coverage report
Current view: top level - boost/http_proto/impl - serializer.hpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 28 28 100.0 %
Date: 2024-01-10 20:31:06 Functions: 11 11 100.0 %

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
       3             : //
       4             : // Distributed under the Boost Software License, Version 1.0. (See accompanying
       5             : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
       6             : //
       7             : // Official repository: https://github.com/cppalliance/http_proto
       8             : //
       9             : 
      10             : #ifndef BOOST_HTTP_PROTO_IMPL_SERIALIZER_HPP
      11             : #define BOOST_HTTP_PROTO_IMPL_SERIALIZER_HPP
      12             : 
      13             : #include <boost/http_proto/detail/except.hpp>
      14             : #include <boost/buffers/range.hpp>
      15             : #include <iterator>
      16             : #include <new>
      17             : #include <utility>
      18             : 
      19             : namespace boost {
      20             : namespace http_proto {
      21             : 
      22             : class serializer::
      23             :     const_buffers_type
      24             : {
      25             :     std::size_t n_ = 0;
      26             :     buffers::const_buffer const* p_ = nullptr;
      27             : 
      28             :     friend class serializer;
      29             : 
      30          12 :     const_buffers_type(
      31             :         buffers::const_buffer const* p,
      32             :         std::size_t n) noexcept
      33          12 :         : n_(n)
      34          12 :         , p_(p)
      35             :     {
      36          12 :     }
      37             : 
      38             : public:
      39             :     using iterator = buffers::const_buffer const*;
      40             :     using const_iterator = iterator;
      41             :     using value_type = buffers::const_buffer;
      42             :     using reference = buffers::const_buffer;
      43             :     using const_reference = buffers::const_buffer;
      44             :     using size_type = std::size_t;
      45             :     using difference_type = std::ptrdiff_t;
      46             : 
      47             :     const_buffers_type() = default;
      48             :     const_buffers_type(
      49             :         const_buffers_type const&) = default;
      50             :     const_buffers_type& operator=(
      51             :         const_buffers_type const&) = default;
      52             : 
      53             :     iterator
      54          23 :     begin() const noexcept
      55             :     {
      56          23 :         return p_;
      57             :     }
      58             : 
      59             :     iterator
      60          23 :     end() const noexcept
      61             :     {
      62          23 :         return p_ + n_;
      63             :     }
      64             : };
      65             : 
      66             : //------------------------------------------------
      67             : 
      68             : template<
      69             :     class ConstBufferSequence,
      70             :     class>
      71             : void
      72           7 : serializer::
      73             : start(
      74             :     message_view_base const& m,
      75             :     ConstBufferSequence&& body)   
      76             : {
      77           7 :     start_init(m);
      78           7 :     auto const& bs =
      79             :         ws_.push(std::forward<
      80             :             ConstBufferSequence>(body));
      81           7 :     std::size_t n = std::distance(
      82             :         buffers::begin(bs),
      83             :         buffers::end(bs));
      84           7 :     buf_ = make_array(n);
      85           7 :     auto p = buf_.data();
      86          14 :     for(buffers::const_buffer b :
      87           7 :             buffers::range(bs))
      88           7 :         *p++ = b;
      89           7 :     start_buffers(m);
      90           7 : }
      91             : 
      92             : template<
      93             :     class Source,
      94             :     class>
      95             : auto
      96           6 : serializer::
      97             : start(
      98             :     message_view_base const& m,
      99             :     Source&& src0) ->
     100             :         typename std::decay<
     101             :             Source>::type&
     102             : {
     103           6 :     start_init(m);
     104           6 :     auto& src = ws_.push(
     105             :         std::forward<
     106             :             Source>(src0));
     107           6 :     start_source(
     108           6 :         m, std::addressof(src));
     109           6 :     return src;
     110             : }
     111             : 
     112             : //------------------------------------------------
     113             : 
     114             : inline
     115             : auto
     116          24 : serializer::
     117             : make_array(std::size_t n) ->
     118             :     detail::array_of_const_buffers 
     119             : {
     120             :     return {
     121             :         ws_.push_array(n,
     122          48 :         buffers::const_buffer{}),
     123          24 :         n };
     124             : }
     125             : 
     126             : } // http_proto
     127             : } // boost
     128             : 
     129             : #endif

Generated by: LCOV version 1.15