pub struct Decoder<R> {
pub max_project_json: u64,
pub max_asset: u64,
pub max_depth: usize,
pub allow_unknown_blocks: bool,
/* private fields */
}Expand description
Decodes a project from a ZIP archive containing a project.json entry.
The decoder supports reading from files or in-memory byte slices and limits the size of the
project JSON to protect against oversized entries. Use Decoder::max_project_json to
configure the limit.
§Examples
let bytes = std::fs::read("project.zip")?;
let mut decoder = Decoder::from_bytes(&bytes)?;
let project = decoder.decode()?;Fields§
§max_project_json: u64Maximum number of bytes allowed when reading project.json.
Defaults to 5 MiB. If the entry exceeds this limit, decoding returns an error.
max_asset: u64Maximum number of bytes allowed when reading an asset.
Defaults to 10 MiB. If the entry exceeds this limit, decoding returns an error.
max_depth: usizeMaximum nesting of C-blocks and reporter inputs.
Defaults to 256. If the block nesting exceeds this limit, decoding returns an error.
allow_unknown_blocks: boolDecides if the decoder returns an error or outputs an crate::model::code::Action::Unknown
or an crate::model::code::Reporter::Unknown when met with an unknown block opcode.
Defaults to false.
Implementations§
Source§impl<R: Read + Seek> Decoder<R>
impl<R: Read + Seek> Decoder<R>
Sourcepub fn new(reader: R) -> Result<Self, Error>
pub fn new(reader: R) -> Result<Self, Error>
Creates a decoder from a readable and seekable ZIP archive.
The JSON size limit defaults to 5 MiB. Returns an error if the archive cannot be opened.
§Examples
let decoder = Decoder::new(Cursor::new(zip_bytes));Sourcepub fn max_project_json(self, bytes: u64) -> Self
pub fn max_project_json(self, bytes: u64) -> Self
Sets the maximum size of the project.json entry in bytes. Defaults to 5 MiB.
Sourcepub fn max_asset(self, bytes: u64) -> Self
pub fn max_asset(self, bytes: u64) -> Self
Sets the maximum size of the asset entries in bytes. Defaults to 10 MiB.
Sourcepub fn max_depth(self, depth: usize) -> Self
pub fn max_depth(self, depth: usize) -> Self
Sets the maximum nesting of C-blocks and reporter inputs. Defaults to 256.
Sourcepub fn allow_unknown_blocks(self, allow: bool) -> Self
pub fn allow_unknown_blocks(self, allow: bool) -> Self
Sets whether to allow unknown blocks. Defaults to false.
Auto Trait Implementations§
impl<R> Freeze for Decoder<R>where
ZipArchive<R>: Freeze,
impl<R> RefUnwindSafe for Decoder<R>where
ZipArchive<R>: RefUnwindSafe,
impl<R> Send for Decoder<R>where
ZipArchive<R>: Send,
impl<R> Sync for Decoder<R>where
ZipArchive<R>: Sync,
impl<R> Unpin for Decoder<R>where
ZipArchive<R>: Unpin,
impl<R> UnsafeUnpin for Decoder<R>where
ZipArchive<R>: UnsafeUnpin,
impl<R> UnwindSafe for Decoder<R>where
ZipArchive<R>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more