fix: change read_pdu to return BytesMut (#143)

This commit is contained in:
Isaiah Becker-Mayer 2023-05-19 13:44:21 +00:00 committed by GitHub
parent 310df4c319
commit 9b7bad65e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View file

@ -85,10 +85,10 @@ where
self.stream.read(&mut self.buf).await
}
pub async fn read_exact(&mut self, length: usize) -> io::Result<Bytes> {
pub async fn read_exact(&mut self, length: usize) -> io::Result<BytesMut> {
loop {
if self.buf.len() >= length {
return Ok(self.buf.split_to(length).freeze());
return Ok(self.buf.split_to(length));
} else {
self.buf.reserve(length - self.buf.len());
}
@ -102,7 +102,7 @@ where
}
}
pub async fn read_pdu(&mut self) -> io::Result<(ironrdp_pdu::Action, Bytes)> {
pub async fn read_pdu(&mut self) -> io::Result<(ironrdp_pdu::Action, BytesMut)> {
loop {
// Try decoding and see if a frame has been received already
match ironrdp_pdu::find_size(self.peek()) {
@ -131,7 +131,7 @@ where
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?
{
Some(length) => {
return self.read_exact(length).await;
return Ok(self.read_exact(length).await?.freeze());
}
None => {
let len = self.read().await?;