pub struct ParsedFile<'a> { /* private fields */ }Expand description
The JSLB file contents, parsed from a slice of bytes.
Use SlabDirectory for a lower-level reading API, or if you don’t
want to materialize the entire file contents into memory.
Implementations§
Source§impl<'a> ParsedFile<'a>
impl<'a> ParsedFile<'a>
Sourcepub fn parse(data: &'a [u8]) -> Result<ParsedFile<'a>, ParseError>
pub fn parse(data: &'a [u8]) -> Result<ParsedFile<'a>, ParseError>
Parse a .jslb byte buffer. Validates the fixed header, the slab
table, that each slab’s bytes fit in data, and that the root
slab has type SlabType::Json. Returns borrowed views into
data.
Sourcepub fn root_json_slab_index(&self) -> usize
pub fn root_json_slab_index(&self) -> usize
Index of the slab that holds the root JSON skeleton.
Sourcepub fn root_json_bytes(&self) -> &'a [u8] ⓘ
pub fn root_json_bytes(&self) -> &'a [u8] ⓘ
Raw bytes of the root JSON skeleton slab.
Sourcepub fn slab_at(&self, p: SlabPlaceholder) -> Result<&SlabBytes<'a>, DecodeError>
pub fn slab_at(&self, p: SlabPlaceholder) -> Result<&SlabBytes<'a>, DecodeError>
Look up a placeholder’s slab. Returns the underlying SlabBytes
for callers that want to handle decoding themselves.
Sourcepub fn read<T: SlabPrimitive>(
&self,
p: SlabPlaceholder,
) -> Result<Vec<T>, DecodeError>
pub fn read<T: SlabPrimitive>( &self, p: SlabPlaceholder, ) -> Result<Vec<T>, DecodeError>
Read a typed-array slab as Vec<T>. The slab’s stored on-disk
type must match T’s on-disk type.
Sourcepub fn read_subjson_bytes(
&self,
p: SlabPlaceholder,
) -> Result<&'a [u8], DecodeError>
pub fn read_subjson_bytes( &self, p: SlabPlaceholder, ) -> Result<&'a [u8], DecodeError>
Read a TYPE_JSON sub-slab as raw bytes. The slab must have type
SlabType::Json. Use this when you want to decode the JSON
yourself instead of going through serde_json::from_slice.
Sourcepub fn read_raw(&self, p: SlabPlaceholder) -> Result<&'a [u8], DecodeError>
pub fn read_raw(&self, p: SlabPlaceholder) -> Result<&'a [u8], DecodeError>
Raw bytes of an arbitrary slab regardless of its type. Useful for
callers that want to do their own decoding (e.g. zero-copy
bytemuck::cast_slice on aligned input; multi-byte slabs are
always little-endian on disk).