GCC Code Coverage Report


Directory: libs/http_proto/include/boost/http_proto/
File: boost/http_proto/impl/serializer.hpp
Date: 2023-02-27 20:43:06
Exec Total Coverage
Lines: 28 28 100.0%
Functions: 11 11 100.0%
Branches: 3 4 75.0%

Line Branch Exec Source
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 14 serializer::
73 start(
74 message_view_base const& m,
75 ConstBufferSequence&& body)
76 {
77 14 start_init(m);
78 14 auto const& bs =
79 ws_.push(std::forward<
80 ConstBufferSequence>(body));
81 14 std::size_t n = std::distance(
82 buffers::begin(bs),
83 buffers::end(bs));
84 14 buf_ = make_array(n);
85 14 auto p = buf_.data();
86
2/2
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 7 times.
28 for(buffers::const_buffer b :
87 14 buffers::range(bs))
88 14 *p++ = b;
89 14 start_buffers(m);
90 14 }
91
92 template<
93 class Source,
94 class>
95 auto
96 12 serializer::
97 start(
98 message_view_base const& m,
99 Source&& src0) ->
100 typename std::decay<
101 Source>::type&
102 {
103 12 start_init(m);
104 12 auto& src = ws_.push(
105 std::forward<
106 Source>(src0));
107 12 start_source(
108 12 m, std::addressof(src));
109 12 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
1/2
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 n };
124 }
125
126 } // http_proto
127 } // boost
128
129 #endif
130