chore: remove some more usages of BytesMut (#9025)

This commit is contained in:
DaniPopes
2024-06-22 10:21:45 +02:00
committed by GitHub
parent a34e41c275
commit f137ca8477
10 changed files with 38 additions and 49 deletions

View File

@ -312,13 +312,14 @@ impl ProtocolProxy {
return Err(io::ErrorKind::InvalidInput.into())
}
let mut masked_bytes = BytesMut::zeroed(msg.len());
masked_bytes[0] = msg[0]
.checked_add(self.shared_cap.relative_message_id_offset())
.ok_or(io::ErrorKind::InvalidInput)?;
let offset = self.shared_cap.relative_message_id_offset();
if offset == 0 {
return Ok(msg);
}
masked_bytes[1..].copy_from_slice(&msg[1..]);
Ok(masked_bytes.freeze())
let mut masked = Vec::from(msg);
masked[0] = masked[0].checked_add(offset).ok_or(io::ErrorKind::InvalidInput)?;
Ok(masked.into())
}
/// Unmasks the message ID of a message received from the wire.