ascii_to_binary

Function ascii_to_binary 

Source
pub fn ascii_to_binary(ascii: &str) -> Result<Box<[u8]>, BinaryGcodeError>
Expand description

Returns a bgcode from an ascii binary

Notes: Maintains the comments ; in the metadata lines that duplicates on the deserialise. Could add a check if they exist on the deserialise side and add them if not. And need to remove them on this side to save space??

Examples found in repository?
examples/serialise_file.rs (line 12)
5fn main() {
6    // Create the path to the gcode file
7    let mut path = env::current_dir().unwrap();
8    path.push("test_files");
9    path.push("mini_cube_b.gcode");
10
11    let gcode = fs::read_to_string(path).unwrap();
12    let binary = ascii_to_binary(&gcode).unwrap();
13    println!("gcode: {}, binary: {}", gcode.len(), binary.len());
14
15    fs::write("tmp/mini_cube_b.bgcode", binary.as_ref()).unwrap();
16}
More examples
Hide additional examples
examples/serde_file.rs (line 15)
5fn main() {
6    // Create the path to the gcode file
7    let mut path = env::current_dir().unwrap();
8    path.push("test_files");
9    path.push("mini_cube_b.gcode");
10
11    // Read the data into memory
12    let before = fs::read_to_string(path).unwrap();
13    println!("Before: {}", before.len());
14    // Convert to binary
15    let binary = ascii_to_binary(&before).unwrap();
16    println!("Binary: {}", binary.len());
17    // Convert back to str
18    let after = binary_to_ascii(&binary, true).unwrap();
19    println!("After: {}", after.len());
20
21    // Lets see what we get
22    fs::write("tmp/serde.gcode", after.as_ref()).unwrap();
23}