codec: add FramedWrite::with_capacity (#7493)

This commit is contained in:
Lucas Black 2025-08-01 02:23:22 -07:00 committed by GitHub
parent ad2e19ffe1
commit 1bc50825f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -47,6 +47,21 @@ where
},
}
}
/// Creates a new `FramedWrite` with the given `encoder` and a buffer of `capacity`
/// initial size.
pub fn with_capacity(inner: T, encoder: E, capacity: usize) -> FramedWrite<T, E> {
FramedWrite {
inner: FramedImpl {
inner,
codec: encoder,
state: WriteFrame {
buffer: BytesMut::with_capacity(capacity),
backpressure_boundary: capacity,
},
},
}
}
}
impl<T, E> FramedWrite<T, E> {