Skip to main content

Crate delbin

Crate delbin 

Source
Expand description

§Delbin

Descriptive Language for Binary Object

Delbin is a Domain Specific Language (DSL) and its supporting library for describing and generating binary data structures, primarily used for Header information generation in embedded firmware packaging scenarios.

§Example

use delbin::{generate, Value};
use std::collections::HashMap;

let dsl = r#"
    @endian = little;
    struct header @packed {
        magic: [u8; 4] = @bytes("FPK\0");
        version: u32 = ${VERSION};
        size: u32 = @sizeof(image);
    }
"#;

let mut env = HashMap::new();
env.insert("VERSION".to_string(), Value::U64(0x0100));

let mut sections = HashMap::new();
sections.insert("image".to_string(), vec![0u8; 1024]);

let result = generate(dsl, &env, &sections).unwrap();
assert_eq!(result.data.len(), 12); // 4 + 4 + 4

Re-exports§

pub use error::DelbinError;
pub use error::DelbinWarning;
pub use error::ErrorCode;
pub use error::Result;
pub use error::WarningCode;
pub use types::Endian;
pub use types::ScalarType;
pub use types::Value;
pub use utils::create_env;
pub use utils::create_sections;
pub use utils::env_insert_int;
pub use utils::env_insert_str;
pub use utils::from_hex_string;
pub use utils::hex_dump;
pub use utils::to_hex_string;

Modules§

ast
Delbin AST definitions
builtin
Delbin built-in function implementations
error
Delbin error type definitions
eval
Delbin evaluator
parser
Delbin parser
types
Delbin type definitions
utils
Delbin utility functions

Structs§

GenerateResult
Generation result

Functions§

generate
Generate binary data according to DSL definition
generate_hex
Generate hexadecimal string
merge
Parameters
parse
Parse binary data according to DSL field layout
validate
Validate DSL without generating output