Skip to main content

ParsedFile

Struct ParsedFile 

Source
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>

Source

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.

Source

pub fn slabs(&self) -> &[SlabBytes<'a>]

All slabs in declaration order.

Source

pub fn root_json_slab_index(&self) -> usize

Index of the slab that holds the root JSON skeleton.

Source

pub fn root_json_bytes(&self) -> &'a [u8] ⓘ

Raw bytes of the root JSON skeleton slab.

Source

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.

Source

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.

Source

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.

Source

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).

Trait Implementations§

Source§

impl<'a> Debug for ParsedFile<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ParsedFile<'a>

§

impl<'a> RefUnwindSafe for ParsedFile<'a>

§

impl<'a> Send for ParsedFile<'a>

§

impl<'a> Sync for ParsedFile<'a>

§

impl<'a> Unpin for ParsedFile<'a>

§

impl<'a> UnsafeUnpin for ParsedFile<'a>

§

impl<'a> UnwindSafe for ParsedFile<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.