Skip to main content

DataWriter

Trait DataWriter 

Source
pub trait DataWriter {
    // Required methods
    fn reserve(&mut self, size: u64) -> Result<(), ParsingError>;
    fn append(&mut self, bytes: &[u8]) -> Result<(), ParsingError>;
    fn pad_to(&mut self, target_size: u64) -> Result<(), ParsingError>;
}
Expand description

An abstraction over an appendable buffer for reading out files.

Required Methods§

Source

fn reserve(&mut self, size: u64) -> Result<(), ParsingError>

Reserves size in the underlying buffer.

Does not affect the write offset within the buffer.

Source

fn append(&mut self, bytes: &[u8]) -> Result<(), ParsingError>

Appends bytes to the buffer.

The internal write offset is incremented by bytes.len(). Partial writes must return an error.

Source

fn pad_to(&mut self, target_size: u64) -> Result<(), ParsingError>

Pads the buffer to target_size.

Moves the buffer’s write offset forward to target_size filling with zeroes. Returns an error if the write offset is larger than target_size.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl DataWriter for Vec<u8>

Source§

fn reserve(&mut self, size: u64) -> Result<(), ParsingError>

Source§

fn append(&mut self, bytes: &[u8]) -> Result<(), ParsingError>

Source§

fn pad_to(&mut self, target_size: u64) -> Result<(), ParsingError>

Implementors§

Source§

impl DataWriter for VmoWriter

Available on Fuchsia only.