⚠️ Warning: This project is a work in progress. The API is unstable and may change without notice.
A Zig implementation of the SCALE (Simple Concatenated Aggregate Little-Endian) encoding and decoding library for Substrate blockchain projects.
SCALE is a lightweight, efficient encoding and decoding codec used extensively in the Polkadot/Substrate ecosystem. This library provides a Zig implementation based on the Parity SCALE codec.
zig fetch --save git+https://github.com/RomarQ/substrate-scale-zig/#HEAD
const std = @import("std");
const scale = @import("scale");
pub fn main() !void {
const allocator = std.heap.page_allocator;
// Encoding
const value: u32 = 42;
const encoded = try scale.encoder.encodeAlloc(allocator, value);
defer allocator.free(encoded);
// Decoding
const result = try scale.decoder.decodeAlloc(u32, encoded, allocator);
std.debug.print("Decoded value: {}\n", .{result.value});
}
Run the tests with:
zig build test --summary all