Struct wiwi::encoding::z85::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> 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.