mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
codec: support byte slices in LengthDelimitedCodec (#8355)
This commit is contained in:
@@ -603,10 +603,10 @@ impl Decoder for LengthDelimitedCodec {
|
||||
}
|
||||
}
|
||||
|
||||
impl Encoder<Bytes> for LengthDelimitedCodec {
|
||||
impl Encoder<&[u8]> for LengthDelimitedCodec {
|
||||
type Error = io::Error;
|
||||
|
||||
fn encode(&mut self, data: Bytes, dst: &mut BytesMut) -> Result<(), io::Error> {
|
||||
fn encode(&mut self, data: &[u8], dst: &mut BytesMut) -> Result<(), io::Error> {
|
||||
let n = data.len();
|
||||
|
||||
if n > self.builder.max_frame_len {
|
||||
@@ -641,12 +641,20 @@ impl Encoder<Bytes> for LengthDelimitedCodec {
|
||||
}
|
||||
|
||||
// Write the frame to the buffer
|
||||
dst.extend_from_slice(&data[..]);
|
||||
dst.extend_from_slice(data);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Encoder<Bytes> for LengthDelimitedCodec {
|
||||
type Error = io::Error;
|
||||
|
||||
fn encode(&mut self, data: Bytes, dst: &mut BytesMut) -> Result<(), io::Error> {
|
||||
Encoder::<&[u8]>::encode(self, data.as_ref(), dst)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for LengthDelimitedCodec {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
|
||||
Reference in New Issue
Block a user