Skip to content

Commit

Permalink
Encoder::buffer_filled and ::len_filled
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraef authored and leshow committed Jun 6, 2024
1 parent 8af42b3 commit c775948
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ pub trait Encodable {

/// Encoder type, holds a mut ref to a buffer
/// that it will write data to and an offset
/// of the next position to write
/// of the next position to write.
///
/// This will start writing from the beginning of the buffer, *not* from the end.
/// The buffer will be grown as needed.
#[derive(Debug)]
pub struct Encoder<'a> {
buffer: &'a mut Vec<u8>,
Expand All @@ -35,6 +38,16 @@ impl<'a> Encoder<'a> {
self.buffer
}

/// Returns the slice of the underlying buffer that has been filled.
pub fn buffer_filled(&self) -> &[u8] {
&self.buffer[..self.offset]
}

/// Returns the number of bytes that have been written to the buffer.
pub fn len_filled(&self) -> usize {
self.offset
}

/// write bytes to buffer
/// Return:
/// number of bytes written
Expand Down

0 comments on commit c775948

Please sign in to comment.