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
3431class 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
553547private:
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
967881private:
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
0 commit comments