Merge branch 'master' of git.kingsome.cn:server_common/librust

This commit is contained in:
azw 2024-05-08 21:10:30 +08:00
commit ea6e02768d
3 changed files with 64 additions and 0 deletions

View File

@ -18,3 +18,4 @@ actix-rt = "1.0.0"
r9 = { path = "../r9" }
r9_macro = { path = "../r9_macro" }
r9_macro_derive = { path = "../r9_macro_derive" }
bytes = "0.5.6"

View File

@ -11,6 +11,7 @@ mod tests {
pub mod timer;
pub mod app;
pub mod protoutils;
pub use timer::Timer;
//pub use app::app;

62
f9/src/protoutils.rs Normal file
View File

@ -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;
}
}