Browse Source

recvice implementiert.

master
Daniel Laptop 1 year ago
parent
commit
2c2b55f776
1 changed files with 31 additions and 0 deletions
  1. 31
    0
      src/bin/message.rs

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

msg.payload[0] = msg_type as u8; msg.payload[0] = msg_type as u8;
msg msg
} }

fn recive(input: Vec<u8>) -> Message {
let byte1 = input.get(0).expect("Fail to Read Byte 1");
let byte2 = input.get(1).expect("Fail to Read Byte 2");
let byte3 = input.get(2).expect("Fail to Read Byte 3");
let byte4 = input.get(3).expect("Fail to Read Byte 4");

let src_id: u32 =
(byte1 << 24) as u32 | (byte2 << 16) as u32 | (byte3 << 8) as u32 | (byte4 << 0) as u32;

let byte5 = input.get(5).expect("Fail to Read Byte 5");
let byte6 = input.get(6).expect("Fail to Read Byte 6");
let byte7 = input.get(7).expect("Fail to Read Byte 7");
let byte8 = input.get(8).expect("Fail to Read Byte 8");

let dest_id: u32 =
(byte5 << 24) as u32 | (byte6 << 16) as u32 | (byte7 << 8) as u32 | (byte8 << 0) as u32;

let byte9 = input.get(9).expect("Fail to Read byte 9");
let byte10 = input.get(10).expect("Fail to Read byte 10");

let size = (byte9 << 8) as u16 | (byte10 << 0) as u16;
assert!(size > 0, "Ungültige size größe size = {}", size);

Message {
src_id: src_id,
dest_id: dest_id,
size: size,
payload: (&input[11..]).to_vec(),
}
}
// Methoden der Klasse // Methoden der Klasse
} }

Loading…
Cancel
Save