pub struct TokenUrEncoder { /* private fields */ }Expand description
Encodes a Token into UR fragments for display as an animated QR code
Each call to next_part returns one fragment
(ur:bytes/…) to be displayed as a single QR frame. The first
fragment_count frames cover the whole token; the
stream is unbounded and frames beyond that are redundant fountain parts,
so a receiver can complete from any sufficiently large subset of frames.
The sender typically loops the frames until the receiver signals
completion.
If the token fits into a single frame, the single-part form
(ur:bytes/<payload>, without fragment indices) is returned, matching
the reference implementations.
V3 tokens are normalized to V4 before serialization, so the encoded token
payload always uses the cashuB… format.
Implementations§
Source§impl TokenUrEncoder
impl TokenUrEncoder
Sourcepub fn new(
token: &Token,
max_fragment_length: usize,
) -> Result<TokenUrEncoder, Error>
pub fn new( token: &Token, max_fragment_length: usize, ) -> Result<TokenUrEncoder, Error>
Creates a new encoder for token
max_fragment_length is the maximum number of payload bytes per QR
frame; DEFAULT_MAX_FRAGMENT_LENGTH is a sane default.
§Errors
Returns an error if max_fragment_length is zero or the token cannot
be converted to V4 or serialized.
Sourcepub fn next_part(&mut self) -> Result<String, Error>
pub fn next_part(&mut self) -> Result<String, Error>
Returns the next UR fragment to display as a QR frame
§Errors
Returns an error if the fragment cannot be encoded.
Sourcepub fn current_index(&self) -> usize
pub fn current_index(&self) -> usize
Returns the number of fragments emitted so far
Sourcepub fn fragment_count(&self) -> usize
pub fn fragment_count(&self) -> usize
Returns the number of fragments the token was split into
Sourcepub fn is_single_fragment(&self) -> bool
pub fn is_single_fragment(&self) -> bool
Returns whether the token fits into a single QR frame