From e3760f4a015e94dd4ad543a535902c5ea8de873c Mon Sep 17 00:00:00 2001 From: EAimTY Date: Fri, 27 Jan 2023 00:30:06 +0900 Subject: [PATCH] moving (un)marshal to crate `tuic` --- tuic-quinn/Cargo.toml | 3 +-- tuic-quinn/src/lib.rs | 11 ++--------- tuic/Cargo.toml | 5 ++++- tuic/src/lib.rs | 18 +++++++++++++++++- {tuic-quinn => tuic}/src/marshal.rs | 6 +++--- {tuic-quinn => tuic}/src/unmarshal.rs | 6 +++--- 6 files changed, 30 insertions(+), 19 deletions(-) rename {tuic-quinn => tuic}/src/marshal.rs (77%) rename {tuic-quinn => tuic}/src/unmarshal.rs (81%) diff --git a/tuic-quinn/Cargo.toml b/tuic-quinn/Cargo.toml index f990737..07e1ec3 100644 --- a/tuic-quinn/Cargo.toml +++ b/tuic-quinn/Cargo.toml @@ -4,9 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] -async-trait = { version = "0.1.62", default-features = false } bytes = { version = "1.3.0", default-features = false, features = ["std"] } futures-util = { version = "0.3.25", default-features = false, features = ["io", "std"] } quinn = { version = "0.9.3", default-features = false, features = ["futures-io"] } thiserror = { version = "1.0.38", default-features = false } -tuic = { path = "../tuic", default-features = false, features = ["model"] } +tuic = { path = "../tuic", default-features = false, features = ["marshal", "model"] } diff --git a/tuic-quinn/src/lib.rs b/tuic-quinn/src/lib.rs index 0cfc3e1..64f3ca2 100644 --- a/tuic-quinn/src/lib.rs +++ b/tuic-quinn/src/lib.rs @@ -1,8 +1,4 @@ -use self::{ - marshal::Marshal, - side::Side, - unmarshal::{Unmarshal, UnmarshalError}, -}; +use self::side::Side; use bytes::Bytes; use futures_util::{io::Cursor, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; use quinn::{ @@ -20,12 +16,9 @@ use tuic::{ AssembleError, Connect as ConnectModel, Connection as ConnectionModel, Packet as PacketModel, }, - protocol::{Address, Header}, + Address, Header, Marshal, Unmarshal, UnmarshalError, }; -mod marshal; -mod unmarshal; - pub mod side { pub struct Client; pub struct Server; diff --git a/tuic/Cargo.toml b/tuic/Cargo.toml index 490a448..526b169 100644 --- a/tuic/Cargo.toml +++ b/tuic/Cargo.toml @@ -4,11 +4,14 @@ version = "0.1.0" edition = "2021" [features] +marshal = ["async-trait", "futures-io"] model = ["parking_lot", "thiserror"] [dependencies] +async-trait = { version = "0.1.62", default-features = false, optional = true } +futures-io = { version = "0.3.25", default-features = false, features = ["std"], optional = true } parking_lot = { version = "0.12.1", default-features = false, optional = true } thiserror = { version = "1.0.38", default-features = false, optional = true } [dev-dependencies] -tuic = { path = ".", features = ["model"] } +tuic = { path = ".", features = ["marshal", "model"] } diff --git a/tuic/src/lib.rs b/tuic/src/lib.rs index 4eaef2f..48dbda5 100644 --- a/tuic/src/lib.rs +++ b/tuic/src/lib.rs @@ -1,6 +1,22 @@ //! The TUIC protocol -pub mod protocol; +mod protocol; + +#[cfg(feature = "marshal")] +mod marshal; + +#[cfg(feature = "marshal")] +mod unmarshal; + +pub use self::protocol::{ + Address, Authenticate, Command, Connect, Dissociate, Header, Heartbeat, Packet, VERSION, +}; + +#[cfg(feature = "marshal")] +pub use self::{ + marshal::Marshal, + unmarshal::{Unmarshal, UnmarshalError}, +}; #[cfg(feature = "model")] pub mod model; diff --git a/tuic-quinn/src/marshal.rs b/tuic/src/marshal.rs similarity index 77% rename from tuic-quinn/src/marshal.rs rename to tuic/src/marshal.rs index 66c2d85..86ddbc9 100644 --- a/tuic-quinn/src/marshal.rs +++ b/tuic/src/marshal.rs @@ -1,10 +1,10 @@ +use crate::protocol::Header; use async_trait::async_trait; -use futures_util::AsyncWrite; +use futures_io::AsyncWrite; use std::io::Error as IoError; -use tuic::protocol::Header; #[async_trait] -pub(super) trait Marshal { +pub trait Marshal { async fn marshal(&self, s: &mut impl AsyncWrite) -> Result<(), IoError>; } diff --git a/tuic-quinn/src/unmarshal.rs b/tuic/src/unmarshal.rs similarity index 81% rename from tuic-quinn/src/unmarshal.rs rename to tuic/src/unmarshal.rs index 1f1c9b7..d933fc8 100644 --- a/tuic-quinn/src/unmarshal.rs +++ b/tuic/src/unmarshal.rs @@ -1,10 +1,10 @@ +use crate::protocol::Header; use async_trait::async_trait; -use futures_util::AsyncRead; +use futures_io::AsyncRead; use thiserror::Error; -use tuic::protocol::Header; #[async_trait] -pub(super) trait Unmarshal +pub trait Unmarshal where Self: Sized, {