Crate foundation_ur

Crate foundation_ur 

Source
Expand description

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.

Modules§

bytewords
Bytewords
collections
Common collection traits.
decoder
Decoder.
encoder
Encoder.
fountain
Fountain encoder/decoder.

Structs§

BaseDecoder
A uniform resource decoder able to receive URIs that encode a fountain part.
BaseEncoder
A uniform resource encoder with an underlying fountain encoding.

Enums§

ParseURError
Errors that can happen during parsing of Uniform Resources.
UR
An uniform resource.

Functions§

max_fragment_len
Calculates the maximum fragment length in bytes that can fit in max_characters, for example, it could be the maximum number of alphanumeric characters in a given QR code.
to_string
Encode a single part UR to a string.

Type Aliases§

Decoder
A decoder.
Encoder
An encoder.
HeaplessDecoder
A static decoder.
HeaplessEncoder
An static encoder.