From 3146caeaf2effb3cd5ede9e13fcd61e5e448dc8d Mon Sep 17 00:00:00 2001 From: azw Date: Wed, 8 May 2024 03:31:57 +0000 Subject: [PATCH] 1 --- f9/Cargo.toml | 1 + f9/src/lib.rs | 1 + f9/src/protoutils.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 f9/src/protoutils.rs diff --git a/f9/Cargo.toml b/f9/Cargo.toml index 8031997..e57da6b 100644 --- a/f9/Cargo.toml +++ b/f9/Cargo.toml @@ -15,3 +15,4 @@ actix-web = "4" r9 = { path = "../r9" } r9_macro = { path = "../r9_macro" } r9_macro_derive = { path = "../r9_macro_derive" } +bytes = "0.5.6" \ No newline at end of file diff --git a/f9/src/lib.rs b/f9/src/lib.rs index a6cc4a5..11888ab 100644 --- a/f9/src/lib.rs +++ b/f9/src/lib.rs @@ -11,6 +11,7 @@ mod tests { pub mod timer; pub mod app; +pub mod protoutils; pub use timer::Timer; //pub use app::app; diff --git a/f9/src/protoutils.rs b/f9/src/protoutils.rs new file mode 100644 index 0000000..e2b870f --- /dev/null +++ b/f9/src/protoutils.rs @@ -0,0 +1,62 @@ +use bytes::{BytesMut}; + +pub struct PackHead { + +} + +pub struct WSProxyPackHead_C { + +} + +pub struct WSProxyPackHead_S { + +} + +impl PackHead { + + pub fn get_size() -> u16 { + return 12 + } + + pub fn get_pack_len(buf: &BytesMut, offset: usize) -> u16 { + let pack_len = (buf[offset + 0] as u16)+ ((buf[offset + 1] as u16) << 8); + return pack_len; + } + + pub fn get_msg_id(buf: &BytesMut, offset: usize) -> u16 { + let msg_id = (buf[offset + 2] as u16)+ ((buf[offset + 3] as u16) << 8); + return msg_id; + } + + pub fn get_seq_id(buf: &BytesMut, offset: usize) -> i32 { + let seq_id = (buf[offset + 4] as i32)+ ((buf[offset + 5] as i32) << 8) + + ((buf[offset + 6] as i32) << 16)+ ((buf[offset + 7] as i32) << 24); + return seq_id; + } + + pub fn get_magic_code(buf: &BytesMut, offset: usize) -> u16 { + let magic_code = (buf[offset + 8] as u16)+ ((buf[offset + 9] as u16) << 8); + return magic_code; + } + + pub fn get_ext_len(buf: &BytesMut, offset: usize) -> u16 { + let ext_len = (buf[offset + 10] as u16)+ ((buf[offset + 11] as u16) << 8); + return ext_len; + } + +} + +impl WSProxyPackHead_C { + + pub fn get_size() -> u16 { + return 24; + } + +} +impl WSProxyPackHead_S { + + pub fn get_size() -> u16 { + return 16; + } + +}