Created
October 18, 2019 00:33
-
-
Save rust-play/5d6fdc353d14eeeceed9e16fff49c5a3 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl From<&Message> for Vec<u8> { | |
fn from(m: &Message) -> Vec<u8> { | |
let mut v: Vec<u8> = Vec::new(); | |
let bs: Vec<u8> = (&m.prelude).into(); | |
v.append(&mut bs.clone()); | |
let crc = m.prelude.crc(); | |
let mut val_bs: Vec<u8> = u32::to_be_bytes(crc).to_vec(); | |
v.append(&mut val_bs); | |
let mut bs: Vec<u8> = (&m.data).into(); | |
v.append(&mut bs); | |
let mut crc_bytes = Message::crc(v.to_vec()); | |
v.append(&mut crc_bytes); | |
v | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment