Struct State

Source
pub struct State { /* private fields */ }
Expand description

State.

Implementations§

Source§

impl State

Source

pub fn new() -> State

Create empty state

Source

pub fn new_with_size(size: usize) -> (State, Box<[u8]>)

Create a state and buffer with an already known size. With this, you can/must skip the preencode step.

Source

pub fn new_with_start_and_end(start: usize, end: usize) -> State

Create a state with a start and end already known.

Source

pub fn from_buffer(buffer: &[u8]) -> State

Create a state from existing buffer.

Source

pub fn start(&self) -> usize

Start value

Source

pub fn set_start(&mut self, value: usize) -> Result<(), EncodingError>

Set start value

Source

pub fn end(&self) -> usize

End value

Source

pub fn set_end(&mut self, value: usize)

Set end value

Source

pub fn add_start(&mut self, increment: usize) -> Result<usize, EncodingError>

Add to start handling overflow and out of bounds.

Source

pub fn add_end(&mut self, increment: usize) -> Result<usize, EncodingError>

Add to end handling overflow

Source

pub fn create_buffer(&self) -> Box<[u8]>

After calling preencode(), this allocates the right size buffer to the heap. Follow this with the same number of encode() steps to fill the created buffer.

Source

pub fn set_byte_to_buffer( &mut self, value: u8, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Safely set single byte to buffer at state.start and then increment state.start, returning new state.start.

Source

pub fn set_slice_to_buffer( &mut self, value: &[u8], buffer: &mut [u8], ) -> Result<usize, EncodingError>

Safely set byte slice to buffer at state.start and then increment state.start with slice length, returning new state.start.

Source

pub fn set_slice_to_buffer_fixed( &mut self, value: &[u8], buffer: &mut [u8], size: usize, ) -> Result<usize, EncodingError>

Safely set byte slice of fixed len to buffer at state.start and then increment state.start with slice length, returning new state.start.

Source

pub fn validate( &mut self, size: usize, buffer: &[u8], ) -> Result<Range<usize>, EncodingError>

Validate size can be decoded from buffer, return current start.

Source

pub fn preencode_str(&mut self, value: &str) -> Result<usize, EncodingError>

Preencode a string slice

Source

pub fn encode_str( &mut self, value: &str, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode a string slice

Source

pub fn decode_string(&mut self, buffer: &[u8]) -> Result<String, EncodingError>

Decode a String

Source

pub fn preencode_uint_var<T>( &mut self, uint: &T, ) -> Result<usize, EncodingError>
where T: From<u32> + Ord,

Preencode a variable length usigned int

Source

pub fn decode_u8(&mut self, buffer: &[u8]) -> Result<u8, EncodingError>

Decode a fixed length u8

Source

pub fn decode_u16(&mut self, buffer: &[u8]) -> Result<u16, EncodingError>

Decode a fixed length u16

Source

pub fn encode_u32_var( &mut self, value: &u32, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode a variable length u32

Source

pub fn encode_u32( &mut self, uint: u32, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode u32 to 4 LE bytes.

Source

pub fn decode_u32_var(&mut self, buffer: &[u8]) -> Result<u32, EncodingError>

Decode a variable length u32

Source

pub fn decode_u32(&mut self, buffer: &[u8]) -> Result<u32, EncodingError>

Decode a fixed length u32

Source

pub fn encode_u64_var( &mut self, value: &u64, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode a variable length u64

Source

pub fn encode_u64( &mut self, uint: u64, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode u64 to 8 LE bytes.

Source

pub fn decode_u64_var(&mut self, buffer: &[u8]) -> Result<u64, EncodingError>

Decode a variable length u64

Source

pub fn decode_u64(&mut self, buffer: &[u8]) -> Result<u64, EncodingError>

Decode a fixed length u64

Source

pub fn preencode_buffer(&mut self, value: &[u8]) -> Result<usize, EncodingError>

Preencode a byte buffer

Source

pub fn preencode_buffer_vec( &mut self, value: &Vec<u8>, ) -> Result<usize, EncodingError>

Preencode a vector byte buffer

Source

pub fn encode_buffer( &mut self, value: &[u8], buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode a byte buffer

Source

pub fn decode_buffer( &mut self, buffer: &[u8], ) -> Result<Box<[u8]>, EncodingError>

Decode a byte buffer

Source

pub fn decode_buffer_vec( &mut self, buffer: &[u8], ) -> Result<Vec<u8>, EncodingError>

Decode a vector byte buffer

Source

pub fn preencode_raw_buffer( &mut self, value: &Vec<u8>, ) -> Result<usize, EncodingError>

Preencode a raw byte buffer. Only possible to use if this is the last value of the State.

Source

pub fn encode_raw_buffer( &mut self, value: &[u8], buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode a raw byte buffer. Only possible to use if this is the last value of the State.

Source

pub fn decode_raw_buffer( &mut self, buffer: &[u8], ) -> Result<Vec<u8>, EncodingError>

Decode a raw byte buffer. Only possible to use if this is the last value of the State.

Source

pub fn preencode_fixed_16(&mut self) -> Result<usize, EncodingError>

Preencode a fixed 16 byte buffer

Source

pub fn encode_fixed_16( &mut self, value: &[u8], buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode a fixed 16 byte buffer

Source

pub fn decode_fixed_16( &mut self, buffer: &[u8], ) -> Result<Box<[u8]>, EncodingError>

Decode a fixed 16 byte buffer

Source

pub fn preencode_fixed_32(&mut self) -> Result<usize, EncodingError>

Preencode a fixed 32 byte buffer

Source

pub fn encode_fixed_32( &mut self, value: &[u8], buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode a fixed 32 byte buffer

Source

pub fn decode_fixed_32( &mut self, buffer: &[u8], ) -> Result<Box<[u8]>, EncodingError>

Decode a fixed 32 byte buffer

Source

pub fn preencode_string_array( &mut self, value: &Vec<String>, ) -> Result<usize, EncodingError>

Preencode a string array

Source

pub fn encode_string_array( &mut self, value: &Vec<String>, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode a String array

Source

pub fn decode_string_array( &mut self, buffer: &[u8], ) -> Result<Vec<String>, EncodingError>

Decode a String array

Source

pub fn preencode_u32_array( &mut self, value: &Vec<u32>, ) -> Result<usize, EncodingError>

Preencode an u32 array

Source

pub fn encode_u32_array( &mut self, value: &Vec<u32>, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode an u32 array

Source

pub fn decode_u32_array( &mut self, buffer: &[u8], ) -> Result<Vec<u32>, EncodingError>

Decode an u32 array

Source

pub fn preencode_fixed_32_array( &mut self, value: &Vec<[u8; 32]>, ) -> Result<usize, EncodingError>

Preencode a fixed 32 byte value array

Source

pub fn encode_fixed_32_array( &mut self, value: &Vec<[u8; 32]>, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode a fixed 32 byte value array

Source

pub fn decode_fixed_32_array( &mut self, buffer: &[u8], ) -> Result<Vec<[u8; 32]>, EncodingError>

Decode a fixed 32 byte value array

Source

pub fn preencode_usize_var( &mut self, value: &usize, ) -> Result<usize, EncodingError>

Preencode a variable length usize

Source

pub fn encode_usize_var( &mut self, value: &usize, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode a variable length usize

Source

pub fn decode_usize_var( &mut self, buffer: &[u8], ) -> Result<usize, EncodingError>

Decode a variable length usize.

Trait Implementations§

Source§

impl Clone for State

Source§

fn clone(&self) -> State

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CompactEncoding<Box<[u8]>> for State

Source§

fn preencode(&mut self, value: &Box<[u8]>) -> Result<usize, EncodingError>

Preencode
Source§

fn encode( &mut self, value: &Box<[u8]>, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode
Source§

fn decode(&mut self, buffer: &[u8]) -> Result<Box<[u8]>, EncodingError>

Decode
Source§

impl CompactEncoding<PartialKeypair> for State

NB: In Javascript’s sodium the secret key contains in itself also the public key, so to maintain binary compatibility, we store the public key in the oplog now twice.

Source§

fn preencode(&mut self, value: &PartialKeypair) -> Result<usize, EncodingError>

Preencode
Source§

fn encode( &mut self, value: &PartialKeypair, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode
Source§

fn decode(&mut self, buffer: &[u8]) -> Result<PartialKeypair, EncodingError>

Decode
Source§

impl CompactEncoding<String> for State

Source§

fn preencode(&mut self, value: &String) -> Result<usize, EncodingError>

Preencode
Source§

fn encode( &mut self, value: &String, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode
Source§

fn decode(&mut self, buffer: &[u8]) -> Result<String, EncodingError>

Decode
Source§

impl CompactEncoding<Vec<[u8; 32]>> for State

Source§

fn preencode(&mut self, value: &Vec<[u8; 32]>) -> Result<usize, EncodingError>

Preencode
Source§

fn encode( &mut self, value: &Vec<[u8; 32]>, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode
Source§

fn decode(&mut self, buffer: &[u8]) -> Result<Vec<[u8; 32]>, EncodingError>

Decode
Source§

impl CompactEncoding<Vec<String>> for State

Source§

fn preencode(&mut self, value: &Vec<String>) -> Result<usize, EncodingError>

Preencode
Source§

fn encode( &mut self, value: &Vec<String>, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode
Source§

fn decode(&mut self, buffer: &[u8]) -> Result<Vec<String>, EncodingError>

Decode
Source§

impl CompactEncoding<Vec<u32>> for State

Source§

fn preencode(&mut self, value: &Vec<u32>) -> Result<usize, EncodingError>

Preencode
Source§

fn encode( &mut self, value: &Vec<u32>, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode
Source§

fn decode(&mut self, buffer: &[u8]) -> Result<Vec<u32>, EncodingError>

Decode
Source§

impl CompactEncoding<Vec<u8>> for State

Source§

fn preencode(&mut self, value: &Vec<u8>) -> Result<usize, EncodingError>

Preencode
Source§

fn encode( &mut self, value: &Vec<u8>, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode
Source§

fn decode(&mut self, buffer: &[u8]) -> Result<Vec<u8>, EncodingError>

Decode
Source§

impl CompactEncoding<u32> for State

Source§

fn preencode(&mut self, value: &u32) -> Result<usize, EncodingError>

Preencode
Source§

fn encode( &mut self, value: &u32, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode
Source§

fn decode(&mut self, buffer: &[u8]) -> Result<u32, EncodingError>

Decode
Source§

impl CompactEncoding<u64> for State

Source§

fn preencode(&mut self, value: &u64) -> Result<usize, EncodingError>

Preencode
Source§

fn encode( &mut self, value: &u64, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode
Source§

fn decode(&mut self, buffer: &[u8]) -> Result<u64, EncodingError>

Decode
Source§

impl CompactEncoding<u8> for State

Source§

fn preencode(&mut self, _: &u8) -> Result<usize, EncodingError>

Preencode
Source§

fn encode( &mut self, value: &u8, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode
Source§

fn decode(&mut self, buffer: &[u8]) -> Result<u8, EncodingError>

Decode
Source§

impl CompactEncoding<usize> for State

Source§

fn preencode(&mut self, value: &usize) -> Result<usize, EncodingError>

Preencode
Source§

fn encode( &mut self, value: &usize, buffer: &mut [u8], ) -> Result<usize, EncodingError>

Encode
Source§

fn decode(&mut self, buffer: &[u8]) -> Result<usize, EncodingError>

Decode
Source§

impl Debug for State

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for State

Source§

fn default() -> State

Create empty state

Auto Trait Implementations§

§

impl Freeze for State

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnwindSafe for State

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more