Crates.io | binarygcode |
lib.rs | binarygcode |
version | |
source | src |
created_at | 2025-03-30 09:18:10.209203+00 |
updated_at | 2025-03-31 09:27:16.942004+00 |
description | A Rust implementation of libbgcode to serialise and deserialise binary gcode. |
homepage | |
repository | https://github.com/jamesgopsill/binarygcode |
max_upload_size | |
id | 1612202 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A no_std
+ alloc
rust library and (coming soon) binary crate to deserialise and serialise binary gcode (.bgcode
) files. The binary gcode specification can be found here.
Please consider supporting the crate by:
Downloading and using the crate.
Raising issues and improvements on the GitHub repo.
Recommending the crate to others.
⭐ the crate on GitHub.
Sponsoring the maintainer.
The crate is still under construction. So far we have managed to complete...
Function | Status |
---|---|
Deserialise | Done |
Serialise | In Progress |
Binary (CLI) | Planned |
Examples can be found in the examples
folder. Below is an example of reading the headers
use std::{
env,
fs::File,
io::{BufReader, Read},
str,
};
use binarygcode::{
common::{BlockKind, Encoding},
deserialiser::{DeserialisedBlock, DeserialisedResult, Deserialiser},
};
use meatpack::{MeatPackResult, Unpacker};
fn main() {
// Create the path to the gcode file
let mut path = env::current_dir().unwrap();
path.push("test_files");
path.push("mini_cube_b.bgcode");
// Open the file and attach a reader
let file = File::open(path).unwrap();
let mut reader = BufReader::new(file);
// Initialise the deserialiser
let mut deserialiser = Deserialiser::default();
// Initialise the read buffer. This could be reading from a file
// or waiting for intermittent bytes from a network transfer.
let mut buf = [0u8; 256];
loop {
// Read bytes into the buffer
let read = reader.read(buf.as_mut_slice()).unwrap();
// Exit when exhausted
if read == 0 {
break;
}
// Provide the read bytes to the deserialiser
deserialiser.digest(&buf[..read]);
// Loop through running deserialise on the deserialisers inner
// buffer with it returning either a header, block or request for more bytes.
// Or an error when deserialising.
loop {
let r = deserialiser.deserialise().unwrap();
match r {
DeserialisedResult::FileHeader(fh) => {
println!("{:?}", fh);
}
DeserialisedResult::Block(b) => {
println!("{}", b);
}
DeserialisedResult::MoreBytesRequired(_) => {
break;
}
}
}
}
}