@@ -7,7 +7,7 @@ use std::{
77 sync:: Arc ,
88} ;
99
10- use bytes:: { Bytes , BytesMut } ;
10+ use bytes:: { BufMut , Bytes , BytesMut } ;
1111use frame:: StreamMetaVec ;
1212use rand:: { Rng , SeedableRng , rngs:: StdRng } ;
1313use thiserror:: Error ;
@@ -757,7 +757,7 @@ impl Connection {
757757 self . receiving_ecn ,
758758 & mut SentFrames :: default ( ) ,
759759 & mut self . spaces [ space_id] ,
760- transmit. buf ,
760+ & mut transmit,
761761 & mut self . stats ,
762762 ) ;
763763 }
@@ -844,7 +844,7 @@ impl Connection {
844844 let sent = self . populate_packet (
845845 now,
846846 space_id,
847- transmit. buf ,
847+ & mut transmit,
848848 builder. max_size ,
849849 builder. exact_number ,
850850 ) ;
@@ -3032,7 +3032,7 @@ impl Connection {
30323032 & mut self ,
30333033 now : Instant ,
30343034 space_id : SpaceId ,
3035- buf : & mut Vec < u8 > ,
3035+ buf : & mut ( impl BufMut + BufLen ) ,
30363036 max_size : usize ,
30373037 pn : u64 ,
30383038 ) -> SentFrames {
@@ -3298,7 +3298,7 @@ impl Connection {
32983298 receiving_ecn : bool ,
32993299 sent : & mut SentFrames ,
33003300 space : & mut PacketSpace ,
3301- buf : & mut Vec < u8 > ,
3301+ buf : & mut impl BufMut ,
33023302 stats : & mut ConnectionStats ,
33033303 ) {
33043304 debug_assert ! ( !space. pending_acks. ranges( ) . is_empty( ) ) ;
@@ -3968,6 +3968,23 @@ fn negotiate_max_idle_timeout(x: Option<VarInt>, y: Option<VarInt>) -> Option<Du
39683968 }
39693969}
39703970
3971+ /// A buffer that can tell how much has been written to it already
3972+ ///
3973+ /// This is commonly used for when a buffer is passed and the user may not write past a
3974+ /// given size. It allows the user of such a buffer to know the current cursor position in
3975+ /// the buffer. The maximum write size is usually passed in the same unit as
3976+ /// [`BufLen::len`]: bytes since the buffer start.
3977+ pub ( crate ) trait BufLen {
3978+ /// Returns the number of bytes written into the buffer so far
3979+ fn len ( & self ) -> usize ;
3980+ }
3981+
3982+ impl BufLen for Vec < u8 > {
3983+ fn len ( & self ) -> usize {
3984+ self . len ( )
3985+ }
3986+ }
3987+
39713988#[ cfg( test) ]
39723989mod tests {
39733990 use super :: * ;
0 commit comments