Skip to content

Commit 69113a4

Browse files
committed
serializer implementation is hidden
1 parent a7de094 commit 69113a4

7 files changed

Lines changed: 656 additions & 688 deletions

File tree

include/boost/http_proto/detail/managed.hpp

Lines changed: 0 additions & 54 deletions
This file was deleted.

include/boost/http_proto/impl/serializer.hpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
#include <boost/http_proto/detail/except.hpp>
1515

16-
#include <numeric>
17-
1816
namespace boost {
1917
namespace http_proto {
2018

@@ -127,11 +125,11 @@ start(
127125
"ConstBufferSequence type requirements not met");
128126

129127
start_init(m);
130-
cbs_gen_ = std::addressof(
131-
ws_.emplace<cbs_gen_impl<typename
132-
std::decay<ConstBufferSequence>::type>>(
128+
start_buffers(
129+
m,
130+
ws().emplace<cbs_gen_impl<typename
131+
std::decay<ConstBufferSequence>::type>>(
133132
std::forward<ConstBufferSequence>(cbs)));
134-
start_buffers(m);
135133
}
136134

137135
template<
@@ -152,11 +150,10 @@ start(
152150
"The Source cannot be constructed with the given arguments");
153151

154152
start_init(m);
155-
auto& src = construct_source<Source>(
153+
auto& source = ws().emplace<Source>(
156154
std::forward<Args>(args)...);
157-
source_ = std::addressof(src);
158-
start_source(m);
159-
return src;
155+
start_source(m, source);
156+
return source;
160157
}
161158

162159
} // http_proto

include/boost/http_proto/serializer.hpp

Lines changed: 38 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@
1111
#ifndef BOOST_HTTP_PROTO_SERIALIZER_HPP
1212
#define BOOST_HTTP_PROTO_SERIALIZER_HPP
1313

14-
#include <boost/http_proto/detail/array_of_const_buffers.hpp>
1514
#include <boost/http_proto/detail/config.hpp>
16-
#include <boost/http_proto/detail/header.hpp>
17-
#include <boost/http_proto/detail/managed.hpp>
1815
#include <boost/http_proto/detail/workspace.hpp>
1916
#include <boost/http_proto/source.hpp>
2017

21-
#include <boost/buffers/circular_buffer.hpp>
2218
#include <boost/buffers/const_buffer_span.hpp>
19+
#include <boost/buffers/mutable_buffer_pair.hpp>
2320
#include <boost/buffers/type_traits.hpp>
2421
#include <boost/rts/context_fwd.hpp>
2522
#include <boost/system/result.hpp>
@@ -32,10 +29,6 @@ namespace http_proto {
3229

3330
// Forward declaration
3431
class message_view_base;
35-
namespace detail {
36-
class serializer_service;
37-
class filter;
38-
} // detail
3932

4033
/** A serializer for HTTP/1 messages
4134
@@ -129,8 +122,9 @@ class serializer
129122
The states of `other` are transferred
130123
to the newly constructed object,
131124
which includes the allocated buffer.
132-
After construction, the moved-from object
133-
left in a valid but unspecified state.
125+
After construction, the only valid
126+
operations on the moved-from object
127+
are destruction and assignment.
134128
135129
Buffer sequences previously obtained
136130
using @ref prepare or @ref stream::prepare
@@ -155,8 +149,13 @@ class serializer
155149
The states of `other` are transferred
156150
`this`, which includes the allocated buffer.
157151
The previous state of `this` are destroyed.
158-
After assignment, the moved-from object
159-
left in a valid but unspecified state.
152+
After assignment, the only valid
153+
operations on the moved-from object are
154+
destruction and assignment.
155+
156+
Buffer sequences previously obtained
157+
using @ref prepare or @ref stream::prepare
158+
remain valid.
160159
161160
@par Postconditions
162161
@code
@@ -225,11 +224,8 @@ class serializer
225224
@ref message_view_base.
226225
*/
227226
void
228-
start(
229-
message_view_base const& m)
230-
{
231-
start_empty(m);
232-
}
227+
BOOST_HTTP_PROTO_DECL
228+
start(message_view_base const& m);
233229

234230
/** Prepare the serializer for a new message with a ConstBufferSequence body.
235231
@@ -544,124 +540,38 @@ class serializer
544540

545541
/** Return true if serialization is complete.
546542
*/
543+
BOOST_HTTP_PROTO_DECL
547544
bool
548-
is_done() const noexcept
549-
{
550-
return state_ == state::start;
551-
}
545+
is_done() const noexcept;
552546

553547
private:
548+
class impl;
554549
class cbs_gen;
555550
template<class>
556551
class cbs_gen_impl;
557552

558-
detail::array_of_const_buffers
559-
make_array(std::size_t n);
560-
561-
template<
562-
class Source,
563-
class... Args,
564-
typename std::enable_if<
565-
std::is_constructible<
566-
Source,
567-
Args...>::value>::type* = nullptr>
568-
Source&
569-
construct_source(Args&&... args)
570-
{
571-
return ws_.emplace<Source>(
572-
std::forward<Args>(args)...);
573-
}
574-
575-
template<
576-
class Source,
577-
class... Args,
578-
typename std::enable_if<
579-
std::is_constructible<
580-
Source,
581-
detail::workspace&,
582-
Args...>::value>::type* = nullptr>
583-
Source&
584-
construct_source(Args&&... args)
585-
{
586-
return ws_.emplace<Source>(
587-
ws_, std::forward<Args>(args)...);
588-
}
589-
590553
BOOST_HTTP_PROTO_DECL
591-
void
592-
start_init(
593-
message_view_base const&);
554+
detail::workspace&
555+
ws();
594556

595557
BOOST_HTTP_PROTO_DECL
596558
void
597-
start_empty(
559+
start_init(
598560
message_view_base const&);
599561

600562
BOOST_HTTP_PROTO_DECL
601563
void
602564
start_buffers(
603-
message_view_base const&);
565+
message_view_base const&,
566+
cbs_gen&);
604567

605568
BOOST_HTTP_PROTO_DECL
606569
void
607570
start_source(
608-
message_view_base const&);
609-
610-
bool
611-
is_header_done() const noexcept;
612-
613-
void
614-
out_init();
615-
616-
buffers::mutable_buffer_pair
617-
out_prepare() noexcept;
618-
619-
void
620-
out_commit(std::size_t) noexcept;
571+
message_view_base const&,
572+
source&);
621573

622-
std::size_t
623-
out_capacity() const noexcept;
624-
625-
void
626-
out_finish() noexcept;
627-
628-
enum class state
629-
{
630-
reset,
631-
start,
632-
header,
633-
body
634-
};
635-
636-
enum class style
637-
{
638-
empty,
639-
buffers,
640-
source,
641-
stream
642-
};
643-
644-
const rts::context* ctx_;
645-
detail::serializer_service* svc_;
646-
detail::workspace ws_;
647-
648-
detail::filter* filter_ = nullptr;
649-
cbs_gen* cbs_gen_ = nullptr;
650-
source* source_ = nullptr;
651-
652-
buffers::circular_buffer out_;
653-
buffers::circular_buffer in_;
654-
detail::array_of_const_buffers prepped_;
655-
buffers::const_buffer tmp_;
656-
657-
detail::managed<
658-
state, state::start> state_;
659-
style style_ = style::empty;
660-
uint8_t chunk_header_len_ = 0;
661-
bool more_input_ = false;
662-
bool is_chunked_ = false;
663-
bool needs_exp100_continue_ = false;
664-
bool filter_done_ = false;
574+
impl* impl_;
665575
};
666576

667577
/** Serializer configuration settings.
@@ -828,9 +738,9 @@ class serializer::stream
828738
@param other The object to move from.
829739
*/
830740
stream(stream&& other) noexcept
831-
: sr_(other.sr_)
741+
: impl_(other.impl_)
832742
{
833-
other.sr_ = nullptr;
743+
other.impl_ = nullptr;
834744
}
835745

836746
/** Move assignment.
@@ -849,15 +759,17 @@ class serializer::stream
849759
stream&
850760
operator=(stream&& other) noexcept
851761
{
852-
std::swap(sr_, other.sr_);
762+
std::swap(impl_, other.impl_);
853763
return *this;
854764
}
855765

856766
/** Return true if the stream is open.
857767
*/
858-
BOOST_HTTP_PROTO_DECL
859768
bool
860-
is_open() const noexcept;
769+
is_open() const noexcept
770+
{
771+
return impl_ != nullptr;
772+
}
861773

862774
/** Return the available capacity.
863775
@@ -961,20 +873,21 @@ class serializer::stream
961873
962874
Closes the stream if open.
963875
*/
964-
BOOST_HTTP_PROTO_DECL
965-
~stream();
876+
~stream()
877+
{
878+
close();
879+
}
966880

967881
private:
968882
friend class serializer;
969883

970884
explicit
971-
stream(
972-
serializer& sr) noexcept
973-
: sr_(&sr)
885+
stream(serializer::impl* impl) noexcept
886+
: impl_(impl)
974887
{
975888
}
976889

977-
serializer* sr_ = nullptr;
890+
serializer::impl* impl_ = nullptr;
978891
};
979892

980893
} // http_proto

src/detail/array_of_const_buffers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
// Official repository: https://github.com/cppalliance/http_proto
99
//
1010

11-
#include <boost/http_proto/detail/array_of_const_buffers.hpp>
11+
#include "src/detail/array_of_const_buffers.hpp"
12+
1213
#include <boost/http_proto/detail/except.hpp>
1314

1415
#include <boost/buffers/sans_prefix.hpp>

include/boost/http_proto/detail/array_of_const_buffers.hpp renamed to src/detail/array_of_const_buffers.hpp

File renamed without changes.

0 commit comments

Comments
 (0)