pack/
pack.rs

1use meatpack::{MeatPackResult, Packer};
2
3fn main() {
4    // Some example gcode.
5    let gcode = "M73 P0 R3
6M73 Q0 S3 ; Hello
7M201 X4000 Y4000 Z200 E2500
8M203 X300 Y300 Z40 E100
9M204 P4000 R1200 T4000
10";
11
12    // Initiliase the packer with buffer size depending
13    // on your application
14    let mut packer = Packer::<64>::default();
15
16    // Feed in the bytes as you receive them and
17    // the packer will return completed lines of
18    // meatpacked gcode to send onwards.
19    for byte in gcode.as_bytes() {
20        let packed = packer.pack(byte);
21        match packed {
22            Ok(MeatPackResult::Line(line)) => {
23                println!("{:?}", line);
24            }
25            Ok(MeatPackResult::WaitingForNextByte) => {}
26            Err(e) => {
27                println!("{:?}", e);
28                panic!()
29            }
30        }
31    }
32}