Struct data_encoding::Builder
[−]
[src]
pub struct Builder { pub symbols: Box<[u8]>, pub values: Box<Array128>, pub bit_order: BitOrder, pub padding: Option<u8>, pub check_trailing_bits: bool, }
Base representation
Convenience methods are provided to edit the fields, although they may be manually edited.
Examples
See the lower-case hexadecimal, upper-case hexadecimal, lower-case permissive hexadecimal, base32, base32hex, base64, and base64url encodings.
Fields
symbols: Box<[u8]>
Symbols
The number of symbols must be 2, 4, 8, 16, 32, or 64. Symbols must be ASCII characters (smaller than 128) and they must be unique.
values: Box<Array128>
Values
A value of 128 means that the index is not a symbol. In other words, if
values[s] != 128
then s
is a symbol (canonical if
symbols[values[s]]
is equal to s
) and values[s]
is its value.
Default is the inverse of symbols.
bit_order: BitOrder
Bit-order
Default is most significant bit first.
padding: Option<u8>
Padding
Default is no padding.
check_trailing_bits: bool
Whether trailing bits are checked
Default is to check trailing bits. This field is ignored when unnecessary (i.e. for base2, base4, and base16).
Methods
impl Builder
[src]
fn new(symbols: &[u8]) -> Builder
Returns a canonical base representation for symbols
By default, the base representation does not have non-canonical symbols. It does not have padding. It is most significant bit first. And it checks the trailing bits if necessary.
Errors
Errors are silently ignored. In other words, if a symbol is not ASCII,
if there are duplicate symbols, or if the number of symbols is not a
power of 2 smaller than 128, then no errors are signaled. However, when
building the base with no_pad
or padded
, if the base
representation is still invalid, an error will be returned.
fn pad(&mut self, pad: u8) -> &mut Builder
Sets padding
fn translate(&mut self, from: &[u8], to: &[u8]) -> &mut Builder
Adds non-canonical symbols
For all i, from[i]
is given the same value as to[i]
.
By default there are only canonical symbols. Non-canonical symbols cannot be produced by encoding functions, but they are recognized by decoding functions. They behave as the canonical symbol of the same value.
Panics
Panics if from
and to
don't have the same length.
Errors
Errors are silently ignored. If a character in from
or to
is not
ASCII then the pair is skipped. If the character in from
is already a
symbol it is overwritten. If the character in to
is not a symbol,
from
is reset.
Examples
let base = Builder::new(b"0123456789abcdef") .translate(b"ABCDEF", b"abcdef").no_pad().unwrap(); assert_eq!(base.decode(b"Bb").unwrap(), vec![0xbb]);
fn least_significant_bit_first(&mut self) -> &mut Builder
Sets bit-order to least significant bit first
fn ignore_trailing_bits(&mut self) -> &mut Builder
Ignores trailing bits
fn no_pad(&self) -> Result<NoPad, BuilderError>
Returns the represented base-conversion encoding
Errors
Returns an error if the base representation is invalid.
fn padded(&self) -> Result<Padded, BuilderError>
Returns the represented padded base-conversion encoding
Errors
Returns an error if the base representation is invalid.
Trait Implementations
impl Debug for Builder
[src]
impl Clone for Builder
[src]
fn clone(&self) -> Builder
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more