-
If you haven't done it already in the last chapter, open the Cargo.toml file that was generated earlier for you.
- Under [dependencies], add the following line:
byteorder = "1.1.0"
- If you want, you can go to byteorder's crates.io page (https://crates.io/crates/byteorder) to check for the newest version and use that one instead.
-
In the bin folder, create a file called binary_files.rs.
-
Add the following code and run it with cargo run --bin binary_files:
1 extern crate byteorder;
2 use byteorder::{ByteOrder, ReadBytesExt, WriteBytesExt, BE,
LE};
3 use std::fs::File;
4 use std::io::{self, BufReader, BufWriter, Read};
5 use std::io::prelude::*;
6
7
8 fn main() {
9 let path = "./bar.bin";
10 write_dummy_protocol(path).expect("Failed write file");
11 let payload = read_protocol(path).expect("Failed to read
file");
12 print!("The protocol contained the following payload...