feat: 使传递给板子的数据结构紧凑。
This commit is contained in:
parent
c44018e633
commit
42d65a559d
38
src/main.rs
38
src/main.rs
@ -64,25 +64,29 @@ async fn main() {
|
||||
|
||||
let state = statistics_manager.get_state().await;
|
||||
|
||||
// stdout()
|
||||
// .write_all(
|
||||
// format!(
|
||||
// "len: {},speed_upload: {}, speed_download: {}, update_direct_speed: {}, download_direct_speed: {}, update_proxy_speed: {}, download_proxy_speed: {}\n",
|
||||
// state.connections,
|
||||
// state.speed_upload,
|
||||
// state.speed_download,
|
||||
// state.direct_upload_speed,
|
||||
// state.direct_download_speed,
|
||||
// state.proxy_upload_speed,
|
||||
// state.proxy_download_speed,
|
||||
// )
|
||||
// .as_bytes(),
|
||||
// )
|
||||
// .await
|
||||
// .unwrap();
|
||||
stdout()
|
||||
.write_all(
|
||||
format!(
|
||||
"len: {},speed_upload: {}, speed_download: {}, update_direct_speed: {}, download_direct_speed: {}, update_proxy_speed: {}, download_proxy_speed: {}\n",
|
||||
state.connections,
|
||||
state.speed_upload,
|
||||
state.speed_download,
|
||||
state.direct_upload_speed,
|
||||
state.direct_download_speed,
|
||||
state.proxy_upload_speed,
|
||||
state.proxy_download_speed,
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let udp_server = udp_server::UdpServer::global().await;
|
||||
let buf = serde_json::to_vec(&state).unwrap();
|
||||
let mut buf = [0; 32];
|
||||
buf[0..8].copy_from_slice(&state.direct_upload_speed.to_le_bytes());
|
||||
buf[8..16].copy_from_slice(&state.direct_download_speed.to_le_bytes());
|
||||
buf[16..24].copy_from_slice(&state.proxy_upload_speed.to_le_bytes());
|
||||
buf[24..32].copy_from_slice(&state.proxy_download_speed.to_le_bytes());
|
||||
udp_server.publish(&buf).await;
|
||||
})
|
||||
};
|
||||
|
@ -62,7 +62,6 @@ impl UdpServer {
|
||||
let socket = UdpSocket::bind((self.listen_addr, self.listen_port)).await?;
|
||||
|
||||
loop {
|
||||
info!("Waiting for data");
|
||||
let (len, addr) = socket.recv_from(&mut buf).await?;
|
||||
|
||||
info!("Received data({}) from {}", len, addr);
|
||||
|
Loading…
Reference in New Issue
Block a user