pub struct State { /* private fields */ }
Expand description
State.
Implementations§
Source§impl State
impl State
Sourcepub fn new_with_size(size: usize) -> (State, Box<[u8]>)
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.
Sourcepub fn new_with_start_and_end(start: usize, end: usize) -> State
pub fn new_with_start_and_end(start: usize, end: usize) -> State
Create a state with a start and end already known.
Sourcepub fn from_buffer(buffer: &[u8]) -> State
pub fn from_buffer(buffer: &[u8]) -> State
Create a state from existing buffer.
Sourcepub fn add_start(&mut self, increment: usize) -> Result<usize, EncodingError>
pub fn add_start(&mut self, increment: usize) -> Result<usize, EncodingError>
Add to start handling overflow and out of bounds.
Sourcepub fn add_end(&mut self, increment: usize) -> Result<usize, EncodingError>
pub fn add_end(&mut self, increment: usize) -> Result<usize, EncodingError>
Add to end handling overflow
Sourcepub fn create_buffer(&self) -> Box<[u8]>
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.
Sourcepub fn set_byte_to_buffer(
&mut self,
value: u8,
buffer: &mut [u8],
) -> Result<usize, EncodingError>
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.
Sourcepub fn set_slice_to_buffer(
&mut self,
value: &[u8],
buffer: &mut [u8],
) -> Result<usize, EncodingError>
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.
Sourcepub fn set_slice_to_buffer_fixed(
&mut self,
value: &[u8],
buffer: &mut [u8],
size: usize,
) -> Result<usize, EncodingError>
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.
Sourcepub fn validate(
&mut self,
size: usize,
buffer: &[u8],
) -> Result<Range<usize>, EncodingError>
pub fn validate( &mut self, size: usize, buffer: &[u8], ) -> Result<Range<usize>, EncodingError>
Validate size
can be decoded from buffer
, return current start.
Sourcepub fn preencode_str(&mut self, value: &str) -> Result<usize, EncodingError>
pub fn preencode_str(&mut self, value: &str) -> Result<usize, EncodingError>
Preencode a string slice
Sourcepub fn encode_str(
&mut self,
value: &str,
buffer: &mut [u8],
) -> Result<usize, EncodingError>
pub fn encode_str( &mut self, value: &str, buffer: &mut [u8], ) -> Result<usize, EncodingError>
Encode a string slice
Sourcepub fn decode_string(&mut self, buffer: &[u8]) -> Result<String, EncodingError>
pub fn decode_string(&mut self, buffer: &[u8]) -> Result<String, EncodingError>
Decode a String
Sourcepub fn preencode_uint_var<T>(
&mut self,
uint: &T,
) -> Result<usize, EncodingError>
pub fn preencode_uint_var<T>( &mut self, uint: &T, ) -> Result<usize, EncodingError>
Preencode a variable length usigned int
Sourcepub fn decode_u8(&mut self, buffer: &[u8]) -> Result<u8, EncodingError>
pub fn decode_u8(&mut self, buffer: &[u8]) -> Result<u8, EncodingError>
Decode a fixed length u8
Sourcepub fn decode_u16(&mut self, buffer: &[u8]) -> Result<u16, EncodingError>
pub fn decode_u16(&mut self, buffer: &[u8]) -> Result<u16, EncodingError>
Decode a fixed length u16
Sourcepub fn encode_u32_var(
&mut self,
value: &u32,
buffer: &mut [u8],
) -> Result<usize, EncodingError>
pub fn encode_u32_var( &mut self, value: &u32, buffer: &mut [u8], ) -> Result<usize, EncodingError>
Encode a variable length u32
Sourcepub fn encode_u32(
&mut self,
uint: u32,
buffer: &mut [u8],
) -> Result<usize, EncodingError>
pub fn encode_u32( &mut self, uint: u32, buffer: &mut [u8], ) -> Result<usize, EncodingError>
Encode u32 to 4 LE bytes.
Sourcepub fn decode_u32_var(&mut self, buffer: &[u8]) -> Result<u32, EncodingError>
pub fn decode_u32_var(&mut self, buffer: &[u8]) -> Result<u32, EncodingError>
Decode a variable length u32
Sourcepub fn decode_u32(&mut self, buffer: &[u8]) -> Result<u32, EncodingError>
pub fn decode_u32(&mut self, buffer: &[u8]) -> Result<u32, EncodingError>
Decode a fixed length u32
Sourcepub fn encode_u64_var(
&mut self,
value: &u64,
buffer: &mut [u8],
) -> Result<usize, EncodingError>
pub fn encode_u64_var( &mut self, value: &u64, buffer: &mut [u8], ) -> Result<usize, EncodingError>
Encode a variable length u64
Sourcepub fn encode_u64(
&mut self,
uint: u64,
buffer: &mut [u8],
) -> Result<usize, EncodingError>
pub fn encode_u64( &mut self, uint: u64, buffer: &mut [u8], ) -> Result<usize, EncodingError>
Encode u64 to 8 LE bytes.
Sourcepub fn decode_u64_var(&mut self, buffer: &[u8]) -> Result<u64, EncodingError>
pub fn decode_u64_var(&mut self, buffer: &[u8]) -> Result<u64, EncodingError>
Decode a variable length u64
Sourcepub fn decode_u64(&mut self, buffer: &[u8]) -> Result<u64, EncodingError>
pub fn decode_u64(&mut self, buffer: &[u8]) -> Result<u64, EncodingError>
Decode a fixed length u64
Sourcepub fn preencode_buffer(&mut self, value: &[u8]) -> Result<usize, EncodingError>
pub fn preencode_buffer(&mut self, value: &[u8]) -> Result<usize, EncodingError>
Preencode a byte buffer
Sourcepub fn preencode_buffer_vec(
&mut self,
value: &Vec<u8>,
) -> Result<usize, EncodingError>
pub fn preencode_buffer_vec( &mut self, value: &Vec<u8>, ) -> Result<usize, EncodingError>
Preencode a vector byte buffer
Sourcepub fn encode_buffer(
&mut self,
value: &[u8],
buffer: &mut [u8],
) -> Result<usize, EncodingError>
pub fn encode_buffer( &mut self, value: &[u8], buffer: &mut [u8], ) -> Result<usize, EncodingError>
Encode a byte buffer
Sourcepub fn decode_buffer(
&mut self,
buffer: &[u8],
) -> Result<Box<[u8]>, EncodingError>
pub fn decode_buffer( &mut self, buffer: &[u8], ) -> Result<Box<[u8]>, EncodingError>
Decode a byte buffer
Sourcepub fn decode_buffer_vec(
&mut self,
buffer: &[u8],
) -> Result<Vec<u8>, EncodingError>
pub fn decode_buffer_vec( &mut self, buffer: &[u8], ) -> Result<Vec<u8>, EncodingError>
Decode a vector byte buffer
Sourcepub fn preencode_raw_buffer(
&mut self,
value: &Vec<u8>,
) -> Result<usize, EncodingError>
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.
Sourcepub fn encode_raw_buffer(
&mut self,
value: &[u8],
buffer: &mut [u8],
) -> Result<usize, EncodingError>
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.
Sourcepub fn decode_raw_buffer(
&mut self,
buffer: &[u8],
) -> Result<Vec<u8>, EncodingError>
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.
Sourcepub fn preencode_fixed_16(&mut self) -> Result<usize, EncodingError>
pub fn preencode_fixed_16(&mut self) -> Result<usize, EncodingError>
Preencode a fixed 16 byte buffer
Sourcepub fn encode_fixed_16(
&mut self,
value: &[u8],
buffer: &mut [u8],
) -> Result<usize, EncodingError>
pub fn encode_fixed_16( &mut self, value: &[u8], buffer: &mut [u8], ) -> Result<usize, EncodingError>
Encode a fixed 16 byte buffer
Sourcepub fn decode_fixed_16(
&mut self,
buffer: &[u8],
) -> Result<Box<[u8]>, EncodingError>
pub fn decode_fixed_16( &mut self, buffer: &[u8], ) -> Result<Box<[u8]>, EncodingError>
Decode a fixed 16 byte buffer
Sourcepub fn preencode_fixed_32(&mut self) -> Result<usize, EncodingError>
pub fn preencode_fixed_32(&mut self) -> Result<usize, EncodingError>
Preencode a fixed 32 byte buffer
Sourcepub fn encode_fixed_32(
&mut self,
value: &[u8],
buffer: &mut [u8],
) -> Result<usize, EncodingError>
pub fn encode_fixed_32( &mut self, value: &[u8], buffer: &mut [u8], ) -> Result<usize, EncodingError>
Encode a fixed 32 byte buffer
Sourcepub fn decode_fixed_32(
&mut self,
buffer: &[u8],
) -> Result<Box<[u8]>, EncodingError>
pub fn decode_fixed_32( &mut self, buffer: &[u8], ) -> Result<Box<[u8]>, EncodingError>
Decode a fixed 32 byte buffer
Sourcepub fn preencode_string_array(
&mut self,
value: &Vec<String>,
) -> Result<usize, EncodingError>
pub fn preencode_string_array( &mut self, value: &Vec<String>, ) -> Result<usize, EncodingError>
Preencode a string array
Sourcepub fn encode_string_array(
&mut self,
value: &Vec<String>,
buffer: &mut [u8],
) -> Result<usize, EncodingError>
pub fn encode_string_array( &mut self, value: &Vec<String>, buffer: &mut [u8], ) -> Result<usize, EncodingError>
Encode a String array
Sourcepub fn decode_string_array(
&mut self,
buffer: &[u8],
) -> Result<Vec<String>, EncodingError>
pub fn decode_string_array( &mut self, buffer: &[u8], ) -> Result<Vec<String>, EncodingError>
Decode a String array
Sourcepub fn preencode_u32_array(
&mut self,
value: &Vec<u32>,
) -> Result<usize, EncodingError>
pub fn preencode_u32_array( &mut self, value: &Vec<u32>, ) -> Result<usize, EncodingError>
Preencode an u32 array
Sourcepub fn encode_u32_array(
&mut self,
value: &Vec<u32>,
buffer: &mut [u8],
) -> Result<usize, EncodingError>
pub fn encode_u32_array( &mut self, value: &Vec<u32>, buffer: &mut [u8], ) -> Result<usize, EncodingError>
Encode an u32 array
Sourcepub fn decode_u32_array(
&mut self,
buffer: &[u8],
) -> Result<Vec<u32>, EncodingError>
pub fn decode_u32_array( &mut self, buffer: &[u8], ) -> Result<Vec<u32>, EncodingError>
Decode an u32 array
Sourcepub fn preencode_fixed_32_array(
&mut self,
value: &Vec<[u8; 32]>,
) -> Result<usize, EncodingError>
pub fn preencode_fixed_32_array( &mut self, value: &Vec<[u8; 32]>, ) -> Result<usize, EncodingError>
Preencode a fixed 32 byte value array
Sourcepub fn encode_fixed_32_array(
&mut self,
value: &Vec<[u8; 32]>,
buffer: &mut [u8],
) -> Result<usize, EncodingError>
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
Sourcepub fn decode_fixed_32_array(
&mut self,
buffer: &[u8],
) -> Result<Vec<[u8; 32]>, EncodingError>
pub fn decode_fixed_32_array( &mut self, buffer: &[u8], ) -> Result<Vec<[u8; 32]>, EncodingError>
Decode a fixed 32 byte value array
Sourcepub fn preencode_usize_var(
&mut self,
value: &usize,
) -> Result<usize, EncodingError>
pub fn preencode_usize_var( &mut self, value: &usize, ) -> Result<usize, EncodingError>
Preencode a variable length usize
Sourcepub fn encode_usize_var(
&mut self,
value: &usize,
buffer: &mut [u8],
) -> Result<usize, EncodingError>
pub fn encode_usize_var( &mut self, value: &usize, buffer: &mut [u8], ) -> Result<usize, EncodingError>
Encode a variable length usize
Sourcepub fn decode_usize_var(
&mut self,
buffer: &[u8],
) -> Result<usize, EncodingError>
pub fn decode_usize_var( &mut self, buffer: &[u8], ) -> Result<usize, EncodingError>
Decode a variable length usize.
Trait Implementations§
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.
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.