| Crates.io | openzl_sddl_derive |
| lib.rs | openzl_sddl_derive |
| version | 0.1.2 |
| created_at | 2025-10-09 01:19:23.272736+00 |
| updated_at | 2025-10-09 01:24:39.70817+00 |
| description | Generate OpenZL SDDL definitions from Rust structs |
| homepage | |
| repository | https://github.com/xangelix/openzl_sddl_derive |
| max_upload_size | |
| id | 1874796 |
| size | 22,381 |
openzl_sddl_derive provides a procedural derive macro for generating OpenZL Simple Data Description Language (SDDL) definitions from Rust structs at compile time.
This crate is a component for integrating Rust applications with the OpenZL compression framework, enabling high-performance, structure-aware compression by describing data layouts declaratively.
OpenZL achieves superior compression ratios by parsing data into homogeneous streams before compression. SDDL is a scripting language used by OpenZL's engine to describe the structure of this data. Instead of writing these SDDL scripts manually, this crate allows you to generate them automatically from your existing Rust struct definitions.
The #[derive(OpenZlSddl)] macro inspects a struct and generates a const SDDL_DEFINITION: &'static str containing the corresponding SDDL "Record" definition. This constant can then be passed to the OpenZL compression library (via FFI) to configure a structure-aware compression graph.
u8, i16, f64, etc.) to their SDDL equivalents (e.g., UInt8, Int16LE, Float64LE).#[sddl(endian = "be")].Vec<T> and String by generating the required two-part SDDL declaration for a length-prefixed array.OpenZlSddl.Add this crate to your Cargo.toml:
[dependencies]
openzl_sddl_derive = "0.1.0" # Replace with the latest version
Simply add #[derive(OpenZlSddl)] to your struct.
use openzl_sddl_derive::OpenZlSddl;
#[derive(OpenZlSddl)]
struct PacketHeader {
version: u8,
sequence: u64,
flags: u32,
}
fn main() {
// The macro generates a constant SDDL_DEFINITION
println!("{}", PacketHeader::SDDL_DEFINITION);
}
This will print the following SDDL script, which describes the PacketHeader struct's memory layout to OpenZL:
PacketHeader = {
version : UInt8;
sequence : UInt64LE;
flags : UInt32LE;
};
The macro supports attributes to control serialization details.
use openzl_sddl_derive::OpenZlSddl;
#[derive(OpenZlSddl)]
struct NetworkMessage {
// Use big-endian for this network-ordered field
#[sddl(endian = "be")]
message_id: u32,
// A variable-length payload.
// The length will be represented by a u32 instead of the default u64.
#[sddl(len_type = "u32")]
payload: Vec<u8>,
// This field is for internal application logic and should not be part
// of the compressed data structure.
#[sddl(skip)]
internal_state: bool,
// A nested struct that also derives OpenZlSddl
footer: MessageFooter,
}
#[derive(OpenZlSddl)]
struct MessageFooter {
checksum: u16,
}
This generates the following comprehensive SDDL script:
NetworkMessage = {
message_id : UInt32BE;
__payload_len : UInt32LE;
payload : UInt8[__payload_len];
footer : MessageFooter;
};
Note: The SDDL for MessageFooter would also need to be registered with the OpenZL engine.
#[sddl(skip)]: Excludes the field from the generated SDDL definition.#[sddl(endian = "le" | "be")]: Specifies the endianness for multi-byte numeric types. Defaults to "le" (little-endian).#[sddl(len_type = "<type>")]: For Vec<T> or String fields, specifies the integer type used to represent the length prefix. Supported types are u8, i8, u16, i16, u32, i32, u64, i64. Defaults to u64.This crate provides the first crucial step for structured compression in Rust: describing the data. The complete workflow requires two additional steps:
serialize() method.This project is licensed under the terms of the MIT license.