Trait basenc::DecodeBuf
[−]
[src]
pub trait DecodeBuf { type Output; unsafe fn alloc(&mut self, len: usize) -> *mut u8; unsafe fn commit(self, len: usize) -> Self::Output; }
Byte buffer receiving decoded input.
Implementors
&mut [u8]
: Stack buffers. Panics if the buffer is too small.Vec<u8>
: Convenience. Appends to the buffer.&mut Vec<u8>
: Efficient buffer reuse. Appends to the buffer.
Examples
Start by calculating the upper_bound
of memory needed for decoding and buffer.alloc(upper_bound)
it.
Write at most upper_bound
of decoded bytes to this memory and buffer.commit(len)
where len
is the actual number of bytes written.
Associated Types
type Output
Required Methods
unsafe fn alloc(&mut self, len: usize) -> *mut u8
Returns uninitialized memory of the requested length.
Increases the underlying buffer's capacity and returns those extra bytes without touching the buffer length.
Safety
The returned memory is logically uninitialized.
unsafe fn commit(self, len: usize) -> Self::Output
Commits len
bytes previously alloc
ated.
Sets the buffer length effectively appending the written bytes to the output.
Returns the decoded bytes.
Safety
The commit
ted len
must be less than or equal to the earlier alloc
ated len
.
The buffer must not be touched in between calling alloc
and commit
.