enable serde feature of bytes, modify struct WriteBlock using Bytes

This commit is contained in:
tom 2022-07-21 16:07:19 +08:00
parent 16b7c7c716
commit 9ab955bb8e
5 changed files with 8 additions and 7 deletions

View File

@ -55,7 +55,7 @@ rpassword = "7.0"
base64 = "0.13"
sysinfo = "0.24"
num_cpus = "1.13"
bytes = "1.2"
bytes = { version = "1.2", features = ["serde"] }
default-net = "0.11.0"
wol-rs = "0.9.1"

View File

@ -11,7 +11,7 @@ protobuf = { version = "3.1", features = ["with-bytes"] }
tokio = { version = "1.20", features = ["full"] }
tokio-util = { version = "0.7", features = ["full"] }
futures = "0.3"
bytes = "1.2"
bytes = { version = "1.2", features = ["serde"] }
log = "0.4"
env_logger = "0.9"
socket2 = { version = "0.3", features = ["reuseport"] }

View File

@ -17,6 +17,7 @@ use parity_tokio_ipc::{
};
use serde_derive::{Deserialize, Serialize};
use std::{collections::HashMap, sync::atomic::Ordering};
use bytes::Bytes;
#[cfg(not(windows))]
use std::{fs::File, io::prelude::*};
@ -63,7 +64,7 @@ pub enum FS {
WriteBlock {
id: i32,
file_num: i32,
data: Vec<u8>,
data: Bytes,
compressed: bool,
},
WriteDone {

View File

@ -1063,7 +1063,7 @@ impl Connection {
self.send_fs(ipc::FS::WriteBlock {
id: block.id,
file_num: block.file_num,
data: block.data.into(),
data: block.data,
compressed: block.compressed,
});
}
@ -1363,8 +1363,8 @@ async fn start_ipc(
file_num,
data,
compressed}) = data {
stream.send(&Data::FS(ipc::FS::WriteBlock{id, file_num, data: Vec::new(), compressed})).await?;
stream.send_raw(data).await?;
stream.send(&Data::FS(ipc::FS::WriteBlock{id, file_num, data: Bytes::new(), compressed})).await?;
stream.send_raw(data.into()).await?;
} else {
stream.send(&data).await?;
}

View File

@ -263,7 +263,7 @@ impl ConnectionManager {
FileTransferBlock {
id,
file_num,
data: data.into(),
data,
compressed,
..Default::default()
},