pub struct Deserialiser {
pub inner: Vec<u8>,
/* private fields */
}Expand description
A binarygcode deserialiser that can parse a bgcode file. It can digest data in chunks and returns header and blocks when available. The block remain compressed so the user can decide which ones they which to decompress.
Fields§
§inner: Vec<u8>Implementations§
Source§impl Deserialiser
impl Deserialiser
Sourcepub fn digest(&mut self, buf: &[u8])
pub fn digest(&mut self, buf: &[u8])
Provide some more bytes for the deserialiser to process/
Examples found in repository?
examples/stream_file.rs (line 35)
9fn main() {
10 // Create the path to the gcode file
11 let mut path = env::current_dir().unwrap();
12 path.push("test_files");
13 //path.push("mini_cube_b.bgcode");
14 path.push("mini_cube_ps2.8.1.bgcode");
15
16 // Open the file and attach a reader
17 let file = File::open(path).unwrap();
18 let mut reader = BufReader::new(file);
19
20 // Initialise the deserialiser
21 let mut deserialiser = Deserialiser::default();
22
23 // Initialise the read buffer. This could be reading from a file
24 // or waiting for intermittent bytes from a network transfer.
25 let mut buf = [0u8; 256];
26
27 loop {
28 // Read bytes into the buffer
29 let read = reader.read(buf.as_mut_slice()).unwrap();
30 // Exit when exhausted
31 if read == 0 {
32 break;
33 }
34 // Provide the read bytes to the deserialiser
35 deserialiser.digest(&buf[..read]);
36
37 // Loop through running deserialise on the deserialisers inner
38 // buffer with it returning either a header, block or request for more bytes.
39 // Or an error when deserialising.
40 loop {
41 let r = deserialiser.deserialise().unwrap();
42 match r {
43 DeserialisedResult::FileHeader(fh) => {
44 println!("{:?}", fh);
45 }
46 DeserialisedResult::Block(b) => {
47 println!("{}", b);
48 }
49 DeserialisedResult::MoreBytesRequired(_) => {
50 break;
51 }
52 }
53 }
54 }
55}Sourcepub fn deserialise(&mut self) -> Result<DeserialisedResult, BinaryGcodeError>
pub fn deserialise(&mut self) -> Result<DeserialisedResult, BinaryGcodeError>
Try and deserialised either a file header or block element from the current digest.
Examples found in repository?
examples/stream_file.rs (line 41)
9fn main() {
10 // Create the path to the gcode file
11 let mut path = env::current_dir().unwrap();
12 path.push("test_files");
13 //path.push("mini_cube_b.bgcode");
14 path.push("mini_cube_ps2.8.1.bgcode");
15
16 // Open the file and attach a reader
17 let file = File::open(path).unwrap();
18 let mut reader = BufReader::new(file);
19
20 // Initialise the deserialiser
21 let mut deserialiser = Deserialiser::default();
22
23 // Initialise the read buffer. This could be reading from a file
24 // or waiting for intermittent bytes from a network transfer.
25 let mut buf = [0u8; 256];
26
27 loop {
28 // Read bytes into the buffer
29 let read = reader.read(buf.as_mut_slice()).unwrap();
30 // Exit when exhausted
31 if read == 0 {
32 break;
33 }
34 // Provide the read bytes to the deserialiser
35 deserialiser.digest(&buf[..read]);
36
37 // Loop through running deserialise on the deserialisers inner
38 // buffer with it returning either a header, block or request for more bytes.
39 // Or an error when deserialising.
40 loop {
41 let r = deserialiser.deserialise().unwrap();
42 match r {
43 DeserialisedResult::FileHeader(fh) => {
44 println!("{:?}", fh);
45 }
46 DeserialisedResult::Block(b) => {
47 println!("{}", b);
48 }
49 DeserialisedResult::MoreBytesRequired(_) => {
50 break;
51 }
52 }
53 }
54 }
55}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Deserialiser
impl RefUnwindSafe for Deserialiser
impl Send for Deserialiser
impl Sync for Deserialiser
impl Unpin for Deserialiser
impl UnwindSafe for Deserialiser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more