Skip to content

Commit

Permalink
Use Bytes serde - increases perf significantly
Browse files Browse the repository at this point in the history
  • Loading branch information
GothAck committed Nov 23, 2021
1 parent a199dc6 commit 3b013d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "tokio-stream-multiplexor"
version = "0.3.1"
version = "0.4.0"
authors = ["Greg \"GothAck\" Miell <rust@greg.gothack.ninja>"]
description = "Stream Multiplexor for tokio with a tcp like interface"
license = "MIT"
Expand All @@ -9,7 +9,7 @@ edition = "2021"
[dependencies]
async-channel = "1.6.1"
bincode = "1.3.3"
bytes = "1.1.0"
bytes = { version = "1.1.0", features = ["serde"] }
futures = "0.3.17"
futures-util = "0.3.17"
rand = "0.8.4"
Expand Down
12 changes: 6 additions & 6 deletions src/frame.rs
@@ -1,4 +1,4 @@
use bytes::{Buf, BytesMut};
use bytes::{Buf, Bytes, BytesMut};
use serde::{Deserialize, Serialize};
use tokio_util::codec::{Decoder, Encoder};

Expand All @@ -10,7 +10,7 @@ pub struct Frame {
pub dport: u16,
pub flag: Flag,
pub seq: u32,
pub data: Vec<u8>,
pub data: Bytes,
}

impl Frame {
Expand All @@ -20,7 +20,7 @@ impl Frame {
dport,
flag,
seq: 0,
data: vec![],
data: Bytes::new(),
}
}

Expand All @@ -30,7 +30,7 @@ impl Frame {
dport: frame.sport,
flag,
seq,
data: vec![],
data: Bytes::new(),
}
}

Expand All @@ -40,7 +40,7 @@ impl Frame {
dport,
flag: Flag::Unset,
seq,
data: data.to_vec(),
data: Bytes::copy_from_slice(data),
}
}

Expand All @@ -50,7 +50,7 @@ impl Frame {
dport,
flag: Flag::Rst,
seq,
data: vec![],
data: Bytes::new(),
}
}
}
Expand Down

0 comments on commit 3b013d7

Please sign in to comment.