From 0a9cb559bd446ea4da127250ac119f06d1e391a3 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sat, 28 May 2022 21:22:25 +0100 Subject: [PATCH] Remove transport module as it was obsolete --- bare_cnr/src/lib.rs | 1 - bare_cnr/src/transport.rs | 43 --------------------------------------- 2 files changed, 44 deletions(-) delete mode 100644 bare_cnr/src/transport.rs diff --git a/bare_cnr/src/lib.rs b/bare_cnr/src/lib.rs index be55a1a..d7daa50 100644 --- a/bare_cnr/src/lib.rs +++ b/bare_cnr/src/lib.rs @@ -1,7 +1,6 @@ use thiserror::Error; mod multiplexer; -mod transport; #[derive(Error, Debug)] pub enum CnrError { diff --git a/bare_cnr/src/transport.rs b/bare_cnr/src/transport.rs deleted file mode 100644 index 561e741..0000000 --- a/bare_cnr/src/transport.rs +++ /dev/null @@ -1,43 +0,0 @@ -use serde::de::DeserializeOwned; -use serde::Serialize; -use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; - -use crate::CnrError; - -pub struct BareTransport { - writer: W, - reader: R, -} - -impl BareTransport { - pub fn new(writer: W, reader: R) -> Self { - Self { writer, reader } - } - - pub async fn write_one_message(&mut self, message: &M) -> Result<(), CnrError> { - let bytes = serde_bare::to_vec(message)?; - self.writer - .write_u32(bytes.len().try_into().unwrap()) - .await?; - self.writer.write_all(&bytes).await?; - // TODO flush? - Ok(()) - } - - pub async fn read_one_message(&mut self) -> Result, CnrError> { - let length = self.reader.read_u32().await? as usize; - // TODO(perf): use uninit? - let mut buf = vec![0u8; length]; - - let first_read = self.reader.read(&mut buf[..]).await?; - if first_read == 0 { - return Ok(None); - } - - if first_read != length { - self.reader.read_exact(&mut buf[first_read..]).await?; - } - - return Ok(Some(serde_bare::from_slice(&buf)?)); - } -}