pub struct Builder { /* private fields */ }Expand description
Builds a container.
use iris_format::{Builder, Container, SectionKind};
let mut builder = Builder::new("readings", 3);
let data = builder.section(SectionKind::Data, b"three rows go here".to_vec());
let bytes = builder.build()?;
let container = Container::parse(&bytes)?;
container.verify()?;
assert_eq!(container.dataset().rows, 3);
assert_eq!(
container.section_bytes(container.section(data).unwrap()),
b"three rows go here"
);Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new(name: impl Into<String>, rows: u64) -> Self
pub fn new(name: impl Into<String>, rows: u64) -> Self
Starts a container for a dataset with this name and this many rows.
Sourcepub fn schema(
&mut self,
encoding: SchemaEncoding,
bytes: impl Into<Vec<u8>>,
) -> &mut Self
pub fn schema( &mut self, encoding: SchemaEncoding, bytes: impl Into<Vec<u8>>, ) -> &mut Self
Sets the schema.
Sourcepub fn section(&mut self, kind: SectionKind, bytes: impl Into<Vec<u8>>) -> u32
pub fn section(&mut self, kind: SectionKind, bytes: impl Into<Vec<u8>>) -> u32
Adds a section and returns the id the rest of the container refers to it by.
Sourcepub fn embed_decoder(
&mut self,
name: impl Into<String>,
abi: (u16, u16),
required: CapabilitySet,
module: impl Into<Vec<u8>>,
) -> u32
pub fn embed_decoder( &mut self, name: impl Into<String>, abi: (u16, u16), required: CapabilitySet, module: impl Into<Vec<u8>>, ) -> u32
Puts a decoder module in the container and points the dataset at it.
Returns the id of the section the module went into, which is worth having for a tool that wants to print the layout.
Sourcepub fn external_decoder(
&mut self,
name: impl Into<String>,
abi: (u16, u16),
required: CapabilitySet,
digest: Digest,
) -> &mut Self
pub fn external_decoder( &mut self, name: impl Into<String>, abi: (u16, u16), required: CapabilitySet, digest: Digest, ) -> &mut Self
Points the dataset at a decoder that lives somewhere else, named by its digest.
Sourcepub fn build(&self) -> Result<Vec<u8>>
pub fn build(&self) -> Result<Vec<u8>>
Lays the container out and returns the bytes.
§Errors
Returns crate::Error::Footer if a name or a schema is longer than the wire format can
describe, which takes four gigabytes of it.
Sourcepub fn build_into(&self, out: impl Write) -> Result<u64>
pub fn build_into(&self, out: impl Write) -> Result<u64>
Lays the container out and writes it, returning how many bytes that was.
The same file as Builder::build, written rather than collected. It matters when the
sections are large: a container written this way costs the sections themselves and about a
kilobyte, where collecting it costs the sections twice over and briefly three times while a
buffer grows. A four gigabyte dataset is the difference between a machine that can write one
and a machine that cannot.
The sections still have to be in memory, because this builder holds them. That is the next thing to fix and the layout is already arranged for it: the directory is at the end, so nothing written earlier depends on anything decided later.
§Errors
Returns crate::Error::Io if the writer refused anything, and
crate::Error::Footer if a name or a schema is longer than the wire format can describe.