| Crates.io | nada |
| lib.rs | nada |
| version | 0.2.2 |
| created_at | 2025-04-25 11:16:34.401891+00 |
| updated_at | 2025-04-30 13:39:40.582167+00 |
| description | Compression-focused encoding for zero-heavy solidity calldata and bytecode |
| homepage | |
| repository | https://github.com/bestinslot-xyz/nada-rs |
| max_upload_size | |
| id | 1648871 |
| size | 28,962 |
Compression-focused encoding for zero-heavy Solidity calldata and bytecode.
nada provides an efficient way to encode and decode byte arrays where runs of 0x00 are replaced with a compact marker (0xFF) followed by the length of the run. This is particularly useful for reducing the size of calldata and bytecode in environments like Ethereum.
0xFF 0x00 is a reserved sequence0xFF 0x01 encodes a single 0xFF0xFF 0x02 encodes a double 0xFF0xFF N (3 ≤ N ≤ 255) encodes N zero bytesThis encoding helps reduce the size of sequences with a high proportion of zero bytes, which are common in Solidity calldata and bytecode.
| Input | Encoded |
|---|---|
[0x00, 0x00, 0x02, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF] |
[0x00, 0x00, 0x02, 0xFF, 0x02, 0xFF, 0x04, 0xFF, 0x01] |
To add nada to your project, use
> cargo add nada
Here is a simple example of how to use the encode and decode functions:
let data = vec![0x01, 0x00, 0x00, 0xFF];
let encoded = nada::encode(data);
let decoded = nada::decode(encoded);
assert_eq!(decoded, Ok(data));
decode returns a DecodeError if the input ends unexpectedly, such as when a 0xFF marker is found without a following run length byte, indicating incomplete or malformed encoded data. It also returns an error if the reserved sequence 0xFF00 is encountered.
Apache License, Version 2.0