Trace message sizes

This commit is contained in:
Jan Trefil 2023-05-13 18:18:19 +02:00
parent 046c5e71ba
commit 0da5dc759f
3 changed files with 10 additions and 2 deletions

1
Cargo.lock generated
View file

@ -806,6 +806,7 @@ dependencies = [
"async-trait", "async-trait",
"bincode", "bincode",
"hmac", "hmac",
"log",
"rand", "rand",
"rkvm-input", "rkvm-input",
"serde", "serde",

View file

@ -16,3 +16,4 @@ thiserror = "1.0.40"
hmac = "0.12.1" hmac = "0.12.1"
sha2 = "0.10.6" sha2 = "0.10.6"
rand = "0.8.5" rand = "0.8.5"
log = "0.4.11"

View file

@ -19,9 +19,13 @@ impl<T: DeserializeOwned + Serialize + Sync> Message for T {
let mut data = vec![0; length.into()]; let mut data = vec![0; length.into()];
stream.read_exact(&mut data).await?; stream.read_exact(&mut data).await?;
options() let data = options()
.deserialize(&data) .deserialize(&data)
.map_err(|err| Error::new(ErrorKind::InvalidData, err)) .map_err(|err| Error::new(ErrorKind::InvalidData, err))?;
log::trace!("Read {} bytes", 2 + length);
Ok(data)
} }
async fn encode<W: AsyncWrite + Send + Unpin>(&self, stream: &mut W) -> Result<(), Error> { async fn encode<W: AsyncWrite + Send + Unpin>(&self, stream: &mut W) -> Result<(), Error> {
@ -37,6 +41,8 @@ impl<T: DeserializeOwned + Serialize + Sync> Message for T {
stream.write_u16(length).await?; stream.write_u16(length).await?;
stream.write_all(&data).await?; stream.write_all(&data).await?;
log::trace!("Wrote {} bytes", 2 + data.len());
Ok(()) Ok(())
} }
} }