@@ -159,7 +159,7 @@ class serializer
159159 std::size_t max_type_erase = 1024 ;
160160 };
161161
162- struct stream ;
162+ class stream ;
163163
164164 /* * Destructor
165165 */
@@ -401,124 +401,76 @@ install_serializer_service(
401401
402402// ------------------------------------------------
403403
404- /* * The type used for caller-provided body data during
405- serialization.
406-
407- @code{.cpp}
408- http_proto::serializer sr(128);
409-
410- http_proto::request req;
411- auto stream = sr.start_stream(req);
412-
413- std::string_view msg = "Hello, world!";
414- auto n = buffers::copy(
415- stream.prepare(),
416- buffers::make_buffer(
417- msg.data(), msg.size()));
418-
419- stream.commit(n);
420-
421- auto cbs = sr.prepare().value();
422- (void)cbs;
423- @endcode
404+ /* * Used for streaming body data during serialization.
424405*/
425- struct serializer ::stream
406+ class serializer ::stream
426407{
427- /* * Constructor.
408+ public:
409+ /* * Constructor
428410
429- The only valid operations on default constructed
430- streams are assignment and destruction.
411+ A default-constructed stream is considered closed.
431412 */
432413 stream () = default ;
433414
434- /* * Constructor.
435-
436- The constructed stream will share the same
437- serializer as `other`.
415+ /* * Move constructor
438416 */
439- stream (stream const & other) = default ;
440-
441- /* * Assignment.
417+ stream (stream&& other)
418+ : sr_(other.sr_)
419+ {
420+ other.sr_ = nullptr ;
421+ }
442422
443- The current stream will share the same serializer
444- as `other`.
423+ /* * Move assignment
445424 */
446- stream& operator = (
447- stream const & other) = default ;
425+ stream&
426+ operator =(stream&& other)
427+ {
428+ std::swap (sr_, other.sr_ );
429+ return *this ;
430+ }
448431
449- /* * A MutableBufferSequence consisting of a buffer pair.
432+ /* * The buffer type returned by @ref prepare
450433 */
451434 using buffers_type =
452435 buffers::mutable_buffer_pair;
453436
454- /* * Returns the remaining available capacity.
455-
456- The returned value represents the available free
457- space in the backing fixed-sized buffers used by the
458- serializer associated with this stream.
459-
460- The capacity is absolute and does not do any
461- accounting for any octets required by a chunked
462- transfer encoding.
437+ /* * Returns `true` if the stream is open
463438 */
464439 BOOST_HTTP_PROTO_DECL
465- std::size_t
466- capacity () const noexcept ;
467-
468- /* * Return true if the stream cannot currently hold
469- additional output data.
470-
471- The fixed-sized buffers maintained by the associated
472- serializer can be sufficiently full from previous
473- calls to @ref stream::commit.
440+ bool
441+ is_open () const noexcept ;
474442
475- This function can be called to determine if the caller
476- should drain the serializer via @ref serializer::consume calls
477- before attempting to fill the buffer sequence
478- returned from @ref stream::prepare.
443+ /* * Returns the available capacity
479444 */
480445 BOOST_HTTP_PROTO_DECL
481- bool
482- is_full () const noexcept ;
483-
484- /* * Returns a MutableBufferSequence for storing
485- serializer input. If `n` bytes are written to the
486- buffer sequence, @ref stream::commit must be called
487- with `n` to update the backing serializer's buffers.
446+ std::size_t
447+ capacity () const noexcept ;
488448
489- The returned buffer sequence is as wide as is
490- possible.
449+ /* * Prepares the buffer for writing
491450
492- @exception std::length_error Thrown if the stream
493- has insufficient capacity and a chunked transfer
494- encoding is being used
451+ Call @ref commit to make data available
452+ to the serializer.
495453 */
496454 BOOST_HTTP_PROTO_DECL
497455 buffers_type
498- prepare () const ;
456+ prepare () const noexcept ;
499457
500- /* * Make `n` bytes available to the serializer.
458+ /* * Commits data to the serializer
501459
502- Once the buffer sequence returned from @ref stream::prepare
503- has been filled, the input can be marked as ready
504- for serialization by using this function.
460+ @param n Number of bytes to commit.
505461
506- @exception std::logic_error Thrown if `commit` is
507- called with 0 .
462+ @throw std::invalid_argument if `n > capacity()`.
463+ @throw std::logic_error if `!is_open()` .
508464 */
509465 BOOST_HTTP_PROTO_DECL
510466 void
511467 commit (std::size_t n) const ;
512468
513- /* * Indicate that no more data is coming and that the
514- body should be treated as complete.
515-
516- @excpeption std::logic_error Thrown if the stream
517- has been previously closed.
469+ /* * Closes the stream
518470 */
519471 BOOST_HTTP_PROTO_DECL
520472 void
521- close () const ;
473+ close () noexcept ;
522474
523475private:
524476 friend class serializer ;
0 commit comments