@@ -27,7 +27,7 @@ impl Default for Decoder {
2727}
2828
2929impl Decoder {
30- pub fn do_poll_write (
30+ fn do_poll_write (
3131 & mut self ,
3232 cx : & mut Context < ' _ > ,
3333 input : & mut PartialBuffer < & [ u8 ] > ,
@@ -73,6 +73,25 @@ impl Decoder {
7373 }
7474 }
7575
76+ pub fn poll_write (
77+ & mut self ,
78+ cx : & mut Context < ' _ > ,
79+ buf : & [ u8 ] ,
80+ writer : Pin < & mut dyn AsyncBufWrite > ,
81+ decoder : & mut impl Decode ,
82+ ) -> Poll < io:: Result < usize > > {
83+ if buf. is_empty ( ) {
84+ return Poll :: Ready ( Ok ( 0 ) ) ;
85+ }
86+
87+ let mut input = PartialBuffer :: new ( buf) ;
88+
89+ match self . do_poll_write ( cx, & mut input, writer, decoder) ? {
90+ Poll :: Pending if input. written ( ) . is_empty ( ) => Poll :: Pending ,
91+ _ => Poll :: Ready ( Ok ( input. written ( ) . len ( ) ) ) ,
92+ }
93+ }
94+
7695 pub fn do_poll_flush (
7796 & mut self ,
7897 cx : & mut Context < ' _ > ,
@@ -169,17 +188,6 @@ macro_rules! impl_decoder {
169188 }
170189
171190 impl <W : AsyncWrite , D : Decode > Decoder <W , D > {
172- fn do_poll_write(
173- self : Pin <& mut Self >,
174- cx: & mut Context <' _>,
175- input: & mut PartialBuffer <& [ u8 ] >,
176- ) -> Poll <io:: Result <( ) >> {
177- let mut this = self . project( ) ;
178-
179- this. inner
180- . do_poll_write( cx, input, this. writer, this. decoder)
181- }
182-
183191 fn do_poll_flush( self : Pin <& mut Self >, cx: & mut Context <' _>) -> Poll <io:: Result <( ) >> {
184192 let mut this = self . project( ) ;
185193
@@ -193,16 +201,9 @@ macro_rules! impl_decoder {
193201 cx: & mut Context <' _>,
194202 buf: & [ u8 ] ,
195203 ) -> Poll <io:: Result <usize >> {
196- if buf. is_empty( ) {
197- return Poll :: Ready ( Ok ( 0 ) ) ;
198- }
199-
200- let mut input = PartialBuffer :: new( buf) ;
204+ let mut this = self . project( ) ;
201205
202- match self . do_poll_write( cx, & mut input) ? {
203- Poll :: Pending if input. written( ) . is_empty( ) => Poll :: Pending ,
204- _ => Poll :: Ready ( Ok ( input. written( ) . len( ) ) ) ,
205- }
206+ this. inner. poll_write( cx, buf, this. writer, this. decoder)
206207 }
207208
208209 fn poll_flush( mut self : Pin <& mut Self >, cx: & mut Context <' _>) -> Poll <io:: Result <( ) >> {
0 commit comments