bragi 0.2.0

Helper crate used in code generated by bragi
Documentation
  • Coverage
  • 94.44%
    17 out of 18 items documented0 out of 16 items with examples
  • Size
  • Source code size: 19.38 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.98 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • managarm/bragi
    7 5 2
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 48cf avdgrinten qookei

bragi

Helper crate used in code generated by bragi and Rust software written for Managarm.

The bindings can be generated from a build.rs file with the help of the bragi-build crate.

Examples

Given the example bragi message:

message ExampleMessage 1 {
head(128):
	uint32 a;
    uint32 b;
}

Including generated bindings

// Include the generated bindings.
bragi::include_binding!(mod bindings = "bindings.rs");

Encoding a message into a Vec<u8>

fn encode_an_example_message() -> std::io::Result<Vec<u8>> {
    // Create an example message
    let msg = bindings::ExampleMessage::new(1337, 420);
    // Encode an example message into a byte buffer.
    let buffer = bragi::message_head_to_bytes(&msg)?;

    Ok(buffer)
}

Decoding a message from a Vec<u8>

fn decode_an_example_message(buffer: &[u8]) -> std::io::Result<()> {
    // Decode an example message
    let msg: bindings::ExampleMessage = bragi::head_from_bytes(buffer)?;
    // Print the decoded message
    println!("a: {}", msg.a());
    println!("b: {}", msg.b());

    Ok(())
}

License

This crate is licensed under the MIT license. See the LICENSE file for more details.