@@ -299,6 +299,7 @@ serializer(rts::context& ctx)
299299 : ctx_(ctx)
300300 , svc_(ctx.get_service<serializer_service>())
301301 , ws_(svc_.space_needed)
302+ , is_done_(true )
302303{
303304}
304305
@@ -307,8 +308,7 @@ serializer::
307308reset () noexcept
308309{
309310 ws_.clear ();
310- is_done_ = false ;
311- is_header_done_ = false ;
311+ is_done_ = true ;
312312}
313313
314314// ------------------------------------------------
@@ -341,9 +341,7 @@ prepare() ->
341341 switch (st_)
342342 {
343343 case style::empty:
344- return const_buffers_type (
345- prepped_.begin (),
346- prepped_.size ());
344+ break ;
347345
348346 case style::buffers:
349347 {
@@ -415,9 +413,32 @@ prepare() ->
415413 switch (st_)
416414 {
417415 case style::empty:
418- return const_buffers_type (
419- prepped_.begin (),
420- prepped_.size ());
416+ {
417+ if (out_capacity () == 0 || filter_done_)
418+ break ;
419+
420+ const auto rs = filter_->process (
421+ buffers::mutable_buffer_span (
422+ out_prepare ()),
423+ {}, // empty input
424+ false );
425+
426+ if (rs.ec .failed ())
427+ {
428+ is_done_ = true ;
429+ return rs.ec ;
430+ }
431+
432+ out_commit (rs.out_bytes );
433+
434+ if (rs.finished )
435+ {
436+ filter_done_ = true ;
437+ out_finish ();
438+ }
439+
440+ break ;
441+ }
421442
422443 case style::buffers:
423444 {
@@ -588,6 +609,7 @@ consume(
588609 if (needs_exp100_continue_)
589610 return ;
590611
612+ ws_.clear ();
591613 is_done_ = true ;
592614}
593615
@@ -612,10 +634,14 @@ start_init(
612634 message_view_base const & m)
613635{
614636 // Precondition violation
615- // if(!is_done_)
616- // detail::throw_logic_error();
637+ if (!is_done_)
638+ detail::throw_logic_error ();
617639
618- reset ();
640+ // TODO: to hold strong exception guarantee
641+ // `is_done_` should be set to true if an
642+ // exception is thrown during the start operation.
643+ is_done_ = false ;
644+ is_header_done_ = false ;
619645
620646 // VFALCO what do we do with
621647 // metadata error code failures?
@@ -677,31 +703,17 @@ serializer::
677703start_empty (
678704 message_view_base const & m)
679705{
680- using mutable_buffer =
681- buffers::mutable_buffer;
682-
683706 start_init (m);
684707 st_ = style::empty;
685708
686- if (!is_chunked_)
687- {
688- prepped_ = make_array (
689- 1 ); // header
690- }
691- else
692- {
693- prepped_ = make_array (
694- 1 + // header
695- 1 ); // final chunk
709+ prepped_ = make_array (
710+ 1 + // header
711+ 2 ); // out buffer pairs
696712
697- mutable_buffer final_chunk = {
698- ws_.reserve_front (
699- final_chunk_len),
700- final_chunk_len };
701- write_final_chunk ({ final_chunk, {} });
713+ out_init ();
702714
703- prepped_[ 1 ] = final_chunk;
704- }
715+ if (!filter_)
716+ out_finish ();
705717
706718 prepped_[0 ] = { m.ph_ ->cbuf , m.ph_ ->size };
707719 more_input_ = false ;
0 commit comments