mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-23 01:16:30 +00:00
Write messages directly onto message buffer instead of allocating on own buffer (#283)
* initial commit * comment * fmt
This commit is contained in:
@@ -493,9 +493,21 @@ where
|
||||
}
|
||||
};
|
||||
|
||||
let mut buf = vec![0u8; len as usize - 4];
|
||||
let mut bytes = BytesMut::with_capacity(len as usize + 1);
|
||||
|
||||
match stream.read_exact(&mut buf).await {
|
||||
bytes.put_u8(code);
|
||||
bytes.put_i32(len);
|
||||
|
||||
bytes.resize(bytes.len() + len as usize - mem::size_of::<i32>(), b'0');
|
||||
|
||||
match stream
|
||||
.read_exact(
|
||||
&mut bytes[mem::size_of::<u8>() + mem::size_of::<i32>()
|
||||
..mem::size_of::<u8>() + mem::size_of::<i32>() + len as usize
|
||||
- mem::size_of::<i32>()],
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => (),
|
||||
Err(_) => {
|
||||
return Err(Error::SocketError(format!(
|
||||
@@ -505,12 +517,6 @@ where
|
||||
}
|
||||
};
|
||||
|
||||
let mut bytes = BytesMut::with_capacity(len as usize + 1);
|
||||
|
||||
bytes.put_u8(code);
|
||||
bytes.put_i32(len);
|
||||
bytes.put_slice(&buf);
|
||||
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user