#blockchain #memory #memory-management #embedded-devices #resources #allocation #uniform

no-std foundation-ur

Implementation of Blockchain Common's Uniform Resources (UR) standard, with static memory allocation for embedded devices while also allowing to use dynamic memory allocation for platforms with more resources

3 releases (breaking)

0.3.0 Jul 15, 2024
0.2.0 May 15, 2024
0.1.0 Feb 16, 2024

#14 in #uniform

Download history 82/week @ 2024-06-27 122/week @ 2024-07-04 445/week @ 2024-07-11 375/week @ 2024-07-18 248/week @ 2024-07-25 183/week @ 2024-08-01 187/week @ 2024-08-08 210/week @ 2024-08-15 303/week @ 2024-08-22 99/week @ 2024-08-29 141/week @ 2024-09-05 192/week @ 2024-09-12 91/week @ 2024-09-19 89/week @ 2024-09-26 199/week @ 2024-10-03 82/week @ 2024-10-10

481 downloads per month

MIT license

155KB
3.5K SLoC

ur is a crate to interact with "Uniform Resources (UR)" encodings of binary data.

The encoding scheme is optimized for transport in URIs and QR codes.

The encoder allows a byte payload to be transmitted in multiple stages, respecting maximum size requirements. Under the hood, a fountain encoder is used to create an unbounded stream of URIs, subsets of which can be recombined at the receiving side into the payload.

For example:

const MAX_FRAGMENT_LENGTH: usize = 5;

let data = "Ten chars!".repeat(10);

encoder.start("bytes", data.as_bytes(), MAX_FRAGMENT_LENGTH);
assert_eq!(
    encoder.next_part().to_string(),
    "ur:bytes/1-20/lpadbbcsiecyvdidatkpfeghihjtcxiabdfevlms"
);

while !decoder.is_complete() {
    let sequence = encoder.current_sequence();
    let part = encoder.next_part();
    // Simulate some communication loss
    if sequence & 1 > 0 {
        decoder.receive(part).unwrap();
    }
}
assert_eq!(decoder.message().unwrap().as_deref(), Some(data.as_bytes()));

The following useful building blocks are also part of the public API:

  • The bytewords module contains functionality to encode byte payloads into a suitable alphabet, achieving hexadecimal byte-per-character efficiency.

  • The fountain module provides an implementation of a fountain encoder, which splits up a byte payload into multiple segments and emits an unbounded stream of parts which can be recombined at the receiving decoder side.

Dependencies

~3MB
~58K SLoC