vtx-format defines the proprietary binary container format (.vtx) used by the VTX plugin system.
It is responsible for encapsulating standard WebAssembly Components (.wasm) into VTX plugin packages equipped with a Magic Header and version control. This ensures that the runtime loads only valid and version-compatible plugins.
Currently, only the V1 format is supported. All multibyte integers are stored in Big-Endian (Note: The current version only involves a single-byte version number, so endianness handling is not yet required).
The file header is fixed at 4 bytes, immediately followed by the raw Wasm Component byte stream.
| Offset | Length (Bytes) | Field | Value / Description |
|---|---|---|---|
| 0x00 | 3 | Magic Prefix | 0x56 0x54 0x58 (ASCII: "VTX") |
| 0x03 | 1 | Version | 0x01 (Current Version) |
| 0x04 | N | Payload | Raw WebAssembly Component binary data |
Add the following to your Cargo.toml:
[dependencies]
vtx-format = "0.1"
Encapsulate raw Wasm bytes into the .vtx format:
use vtx_format::encode_v1;
fn main() {
let wasm_bytes = std::fs::read("plugin.wasm").unwrap();
// Automatically adds the "VTX\x01" header
let vtx_data = encode_v1(&wasm_bytes);
std::fs::write("plugin.vtx", vtx_data).unwrap();
}Parse a .vtx file and verify the header:
use vtx_format::{decode, VtxFormatError};
fn main() -> Result<(), VtxFormatError> {
let data = std::fs::read("plugin.vtx").unwrap();
// Returns (version, raw payload slice)
let (version, payload) = decode(&data)?;
println!("Detected VTX version: {}", version);
println!("Payload size: {} bytes", payload.len());
Ok(())
}The library provides the VtxFormatError enum to handle parsing errors:
TooShort: Data length is less than 4 bytes.InvalidPrefix: Header is not "VTX".UnsupportedVersion(u8): Encountered an unknown version number.
MIT License