Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created October 18, 2019 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/5d6fdc353d14eeeceed9e16fff49c5a3 to your computer and use it in GitHub Desktop.
Save rust-play/5d6fdc353d14eeeceed9e16fff49c5a3 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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