Expand description
§OpenZL SDDL Derive
This crate provides a procedural derive macro #[derive(OpenZlSddl)] for
generating OpenZL Simple Data Description
Language (SDDL) definitions from Rust structs at compile time.
§Overview
OpenZL is a compression framework that achieves high compression ratios by
understanding the structure of the data it compresses. The Simple Data
Description Language (SDDL) is a scripting language used to describe this
structure to the OpenZL engine.
This macro automates the creation of SDDL “Record” definitions by inspecting
a Rust struct, effectively creating a bridge between Rust’s type system and
OpenZL’s data description format. The generated SDDL string can be used with
the OpenZL library (via FFI) to enable efficient, structure-aware compression.
§Usage
Add this to your Cargo.toml:
[dependencies]
openzl_sddl_derive = "0.1.0" # Use the latest versionThen, apply the #[derive(OpenZlSddl)] attribute to your structs. The macro
will generate a const SDDL_DEFINITION: &'static str associated with the struct.
§Basic Example
use openzl_sddl_derive::OpenZlSddl;
#[derive(OpenZlSddl)]
struct PacketHeader {
version: u8,
sequence: u64,
}
// The generated SDDL can be accessed via the associated constant:
const SDDL: &str = PacketHeader::SDDL_DEFINITION;
// Generated SDDL:
// PacketHeader = {
// version : UInt8;
// sequence : UInt64LE;
// };§Attributes for Fine-Grained Control
Attributes can be used to control endianness, handle variable-length data, and exclude fields.
use openzl_sddl_derive::OpenZlSddl;
#[derive(OpenZlSddl)]
struct NetworkMessage {
/// Use big-endian for this network-ordered field.
#[sddl(endian = "be")]
message_id: u32,
/// For Vec<T>, specify the integer type for the length prefix.
/// Defaults to "u64".
#[sddl(len_type = "u32")]
payload: Vec<u8>,
/// This field is for application logic and will be ignored by the macro.
#[sddl(skip)]
internal_state: bool,
}
// Generated SDDL:
// NetworkMessage = {
// message_id : UInt32BE;
// __payload_len : UInt32LE;
// payload : UInt8[__payload_len];
// };§Supported Features
- Primitive Types:
u8-u64,i8-i64,f32,f64. - Endianness: Defaults to little-endian (
le), configurable with#[sddl(endian = "be")]. - Variable-Length Types:
Vec<T>andString. The length prefix type is configurable with#[sddl(len_type = "...")]. - Nested Structs: Fields can be other structs that also derive
OpenZlSddl. - Field Exclusion:
#[sddl(skip)]to ignore fields.
Derive Macros§
- Open
ZlSddl - A procedural macro to generate an
OpenZLSDDL definition from a Rust struct.