wiwi::encoding::z85

Struct EncodedReprInfo

Source
pub struct EncodedReprInfo {
    pub frames: usize,
    pub remainder: usize,
    pub needed_capacity: usize,
}
Expand description

Various details about a slice and it’s encoded output bytes, including number of full frames, remainder, and how much capacity is needed to hold all the encoded bytes

§Safety

All fields on this struct are marked pub, meaning anyone is allowed to directly access and modify them. Don’t accept any instances of this struct from nontrusted sources, nor construct instances from raw data taken from nontrusted sources.

On the contrary, you can trust and rely on the output directly from the for_input_len associated function, including in unsafe contexts. The body of this function is heavily documented.

Fields§

§frames: usize

The amount of full frames (eg. amount of full chunks of 4 bytes)

§remainder: usize

The amount of remainder bytes, strictly less than 4 (frame size)

§needed_capacity: usize

The amount of capacity required to fit all the encoded data into

This is calculated by summing up the following values:

  • Space needed for full frames is frames * 5, since every frame is a chunk of 4 bytes that gets encoded into a frame of 5 bytes
  • Space needed for remainder bytes:
    • If no remainder, then 0. Simple enough :p
      • This also implies that if the input does not need to be padded to a len that is a multiple of 4, no padding is needed. In this case, the numbers/calculations here are compliant with the Z85 spec.
    • If there is remainder, it is 5 + 1. The remainder bytes will be padded to a full frame of 4, then encoded as a full frame, yielding 5. Then, one extra byte is added onto the end to encode the amount of padding we have added (ex. 1 for 3 remainder bytes and 1 padding).

Implementations§

Source§

impl EncodedReprInfo

Source

pub fn for_input_len(input_len: usize) -> Self

Calculates the values

See documentation on EncodedReprInfo and on the individual fields for more information.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Encode for T

Source§

fn encode<E>(self) -> <E as Encoding>::EncodeOutput
where T: Encodable<E>, E: Encoding,

Source§

fn decode<E>(self) -> <E as Encoding>::DecodeOutput
where T: Decodable<E>, E: Encoding,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.