Trait s2n_quic_core::havoc::Encoder
source · [−]pub trait Encoder {
fn write_sized<F>(&mut self, len: usize, write: F)
where
F: for<'_> FnOnce(&mut [u8]);
fn write_slice(&mut self, slice: &[u8]);
fn write_repeated(&mut self, count: usize, value: u8);
fn capacity(&self) -> usize;
fn len(&self) -> usize;
fn encode<T>(&mut self, value: &T)
where
T: EncoderValue,
{ ... }
fn encode_with_len_prefix<Len, T>(&mut self, value: &T)
where
Len: TryFrom<usize> + EncoderValue,
T: EncoderValue,
<Len as TryFrom<usize>>::Error: Debug,
{ ... }
fn is_empty(&self) -> bool { ... }
fn remaining_capacity(&self) -> usize { ... }
}Required Methods
fn write_sized<F>(&mut self, len: usize, write: F) where
F: for<'_> FnOnce(&mut [u8]),
fn write_sized<F>(&mut self, len: usize, write: F) where
F: for<'_> FnOnce(&mut [u8]),
Calls write with a slice of len bytes at the current write position
fn write_slice(&mut self, slice: &[u8])
fn write_slice(&mut self, slice: &[u8])
Copies the slice into the buffer
fn write_repeated(&mut self, count: usize, value: u8)
fn write_repeated(&mut self, count: usize, value: u8)
Repeatedly write a byte value for a given count
let mut buffer = vec![255; 1024];
let mut encoder = EncoderBuffer::new(&mut buffer);
encoder.encode(&1u8);
encoder.write_repeated(4, 0);
assert_eq!(&buffer[0..6], &[1, 0, 0, 0, 0, 255]);Provided Methods
fn encode<T>(&mut self, value: &T) where
T: EncoderValue,
fn encode<T>(&mut self, value: &T) where
T: EncoderValue,
Encode the given EncoderValue into the buffer
fn encode_with_len_prefix<Len, T>(&mut self, value: &T) where
Len: TryFrom<usize> + EncoderValue,
T: EncoderValue,
<Len as TryFrom<usize>>::Error: Debug,
fn encode_with_len_prefix<Len, T>(&mut self, value: &T) where
Len: TryFrom<usize> + EncoderValue,
T: EncoderValue,
<Len as TryFrom<usize>>::Error: Debug,
Encode the given EncoderValue into the buffer with a prefix of Len
fn remaining_capacity(&self) -> usize
fn remaining_capacity(&self) -> usize
Returns the number of available bytes in the buffer