pub struct BurnpackWriter { /* private fields */ }Expand description
Writer for creating Burnpack files
Implementations§
Source§impl BurnpackWriter
impl BurnpackWriter
Sourcepub fn new(snapshots: Vec<TensorSnapshot>) -> Self
pub fn new(snapshots: Vec<TensorSnapshot>) -> Self
Create a new writer
Sourcepub fn with_metadata(self, key: &str, value: &str) -> Self
pub fn with_metadata(self, key: &str, value: &str) -> Self
Builder pattern: add metadata and return self
Sourcepub fn size(&self) -> Result<usize, BurnpackError>
pub fn size(&self) -> Result<usize, BurnpackError>
Calculate the total size needed for the burnpack data
This is useful when you want to pre-allocate a buffer for write_into().
The size includes padding bytes for both metadata alignment and tensor alignment.
Sourcepub fn write_into(&self, buffer: &mut [u8]) -> Result<(), BurnpackError>
pub fn write_into(&self, buffer: &mut [u8]) -> Result<(), BurnpackError>
Write burnpack data into a caller-provided buffer
The buffer must be large enough to hold all data. Use size() to determine
the required buffer size. If the buffer is too small, this will return an error.
This allows the caller to control buffer allocation, enabling optimizations like:
- Buffer reuse across multiple writes
- Custom allocators
- Pinned memory for GPU transfers
§Arguments
buffer- Mutable slice to write data into. Must be at leastsize()bytes.
Sourcepub fn to_bytes(&self) -> Result<Bytes, BurnpackError>
pub fn to_bytes(&self) -> Result<Bytes, BurnpackError>
Write to a byte buffer (convenience method)
This allocates a buffer internally and writes the burnpack data.
For more control over buffer allocation, use size() + write_into().
Sourcepub fn write_to_file<P: AsRef<Path>>(
&self,
path: P,
) -> Result<(), BurnpackError>
pub fn write_to_file<P: AsRef<Path>>( &self, path: P, ) -> Result<(), BurnpackError>
Write directly to a file (more memory efficient for large models)