| 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/iterators.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 : bs) |
| 87 | 14 | *p++ = b; | |
| 88 | 14 | start_buffers(m); | |
| 89 | 14 | } | |
| 90 | |||
| 91 | template< | ||
| 92 | class Source, | ||
| 93 | class> | ||
| 94 | auto | ||
| 95 | 12 | serializer:: | |
| 96 | start( | ||
| 97 | message_view_base const& m, | ||
| 98 | Source&& src0) -> | ||
| 99 | typename std::decay< | ||
| 100 | Source>::type& | ||
| 101 | { | ||
| 102 | 12 | start_init(m); | |
| 103 | 12 | auto& src = ws_.push( | |
| 104 | std::forward< | ||
| 105 | Source>(src0)); | ||
| 106 | 12 | start_source( | |
| 107 | 12 | m, std::addressof(src)); | |
| 108 | 12 | return src; | |
| 109 | } | ||
| 110 | |||
| 111 | //------------------------------------------------ | ||
| 112 | |||
| 113 | inline | ||
| 114 | auto | ||
| 115 | 24 | serializer:: | |
| 116 | make_array(std::size_t n) -> | ||
| 117 | detail::array_of_const_buffers | ||
| 118 | { | ||
| 119 | return { | ||
| 120 | ws_.push_array(n, | ||
| 121 | 48 | buffers::const_buffer{}), | |
| 122 |
1/2✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | n }; |
| 123 | } | ||
| 124 | |||
| 125 | } // http_proto | ||
| 126 | } // boost | ||
| 127 | |||
| 128 | #endif | ||
| 129 |