Daniel Laptop 2 years ago
parent
commit
b654f2db36
1 changed files with 23 additions and 0 deletions
  1. 23
    0
      src/bin/message.rs

+ 23
- 0
src/bin/message.rs View File

@@ -1,7 +1,10 @@
<<<<<<< HEAD
use std::{
io::{BufReader, Read},
net::TcpStream,
};
=======
>>>>>>> f36772d9e5c0507015de02b8c71ff25d84789b98

const KEYLENGTH: u8 = 32;

@@ -45,6 +48,26 @@ impl Message {
msg.payload[0] = msg_type as u8;
msg
}
fn creat_vec(&mut self) -> Vec<u8> {
let mut vec: Vec<u8> = vec![0; (10 + self.size).into()];

vec[0] = ((self.src_id >> 24) & 0xff) as u8;
vec[1] = ((self.src_id >> 16) & 0xff) as u8;
vec[2] = ((self.src_id >> 8) & 0xff) as u8;
vec[3] = (self.src_id & 0xff) as u8;
vec[4] = ((self.dest_id >> 24) & 0xff) as u8;
vec[5] = ((self.dest_id >> 16) & 0xff) as u8;
vec[6] = ((self.dest_id >> 8) & 0xff) as u8;
vec[7] = (self.dest_id & 0xff) as u8;
vec[8] = ((self.size >> 8) & 0xff) as u8;
vec[9] = (self.size & 0xff) as u8;


for i in 10..(10 + self.size).into(){
vec[i] = self.payload[i - 10];
}
vec
}

fn recive(stream: TcpStream) -> Message {
let buffreader = BufReader::new(stream);

Loading…
Cancel
Save