pub struct Reader { /* private fields */ }
Expand description
OMF reader object.
Typical usage pattern is:
- Create the reader object.
- Optional: retrieve the file version with
reader.version()
. - Optional: adjust the limits with
reader.set_limits(...)
. - Read the project from the file with
reader.project()
. - Iterate through the project’s contents to find the elements and attributes you want to load.
- For each of those items load the array or image data.
Warning: When loading arrays and images from OMF files, beware of “zip bombs” where data is maliciously crafted to expand to an excessive size when decompressed, leading to a potential denial of service attack. Use the limits provided check arrays sizes before allocating memory.
Implementations§
source§impl Reader
impl Reader
sourcepub fn array_scalars(&self, array: &Array<Scalar>) -> Result<Scalars, Error>
pub fn array_scalars(&self, array: &Array<Scalar>) -> Result<Scalars, Error>
Read an array_type::Scalar
array.
sourcepub fn array_vertices(&self, array: &Array<Vertex>) -> Result<Vertices, Error>
pub fn array_vertices(&self, array: &Array<Vertex>) -> Result<Vertices, Error>
Read an array_type::Vertex
array.
sourcepub fn array_segments(
&self,
array: &Array<Segment>,
) -> Result<GenericPrimitives<2>, Error>
pub fn array_segments( &self, array: &Array<Segment>, ) -> Result<GenericPrimitives<2>, Error>
Read an array_type::Segment
array.
sourcepub fn array_triangles(
&self,
array: &Array<Triangle>,
) -> Result<GenericPrimitives<3>, Error>
pub fn array_triangles( &self, array: &Array<Triangle>, ) -> Result<GenericPrimitives<3>, Error>
Read an array_type::Triangle
array.
sourcepub fn array_names(&self, array: &Array<Name>) -> Result<Names, Error>
pub fn array_names(&self, array: &Array<Name>) -> Result<Names, Error>
Read an array_type::Name
array.
sourcepub fn array_gradient(&self, array: &Array<Gradient>) -> Result<Gradient, Error>
pub fn array_gradient(&self, array: &Array<Gradient>) -> Result<Gradient, Error>
Read an array_type::Gradient
array.
sourcepub fn array_texcoords(
&self,
array: &Array<Texcoord>,
) -> Result<Texcoords, Error>
pub fn array_texcoords( &self, array: &Array<Texcoord>, ) -> Result<Texcoords, Error>
Read an array_type::Texcoord
array.
sourcepub fn array_boundaries(
&self,
array: &Array<Boundary>,
) -> Result<Boundaries, Error>
pub fn array_boundaries( &self, array: &Array<Boundary>, ) -> Result<Boundaries, Error>
Read an array_type::Boundary
array.
sourcepub fn array_regular_subblocks(
&self,
array: &Array<RegularSubblock>,
) -> Result<RegularSubblocks, Error>
pub fn array_regular_subblocks( &self, array: &Array<RegularSubblock>, ) -> Result<RegularSubblocks, Error>
Read an array_type::RegularSubblock
array.
sourcepub fn array_freeform_subblocks(
&self,
array: &Array<FreeformSubblock>,
) -> Result<FreeformSubblocks, Error>
pub fn array_freeform_subblocks( &self, array: &Array<FreeformSubblock>, ) -> Result<FreeformSubblocks, Error>
Read an array_type::FreeformSubblock
array.
sourcepub fn array_numbers(&self, array: &Array<Number>) -> Result<Numbers, Error>
pub fn array_numbers(&self, array: &Array<Number>) -> Result<Numbers, Error>
Read an array_type::Number
array.
sourcepub fn array_indices(&self, array: &Array<Index>) -> Result<Indices, Error>
pub fn array_indices(&self, array: &Array<Index>) -> Result<Indices, Error>
Read an array_type::Index
array.
sourcepub fn array_vectors(&self, array: &Array<Vector>) -> Result<Vectors, Error>
pub fn array_vectors(&self, array: &Array<Vector>) -> Result<Vectors, Error>
Read an array_type::Vector
array.
sourcepub fn array_text(&self, array: &Array<Text>) -> Result<Text, Error>
pub fn array_text(&self, array: &Array<Text>) -> Result<Text, Error>
Read a `array_type::Text array.
sourcepub fn array_booleans(&self, array: &Array<Boolean>) -> Result<Booleans, Error>
pub fn array_booleans(&self, array: &Array<Boolean>) -> Result<Booleans, Error>
Read an array_type::Boolean
array.
sourcepub fn array_colors(&self, array: &Array<Color>) -> Result<Colors, Error>
pub fn array_colors(&self, array: &Array<Color>) -> Result<Colors, Error>
Read an array_type::Color
array.
source§impl Reader
impl Reader
sourcepub fn new(file: File) -> Result<Self, Error>
pub fn new(file: File) -> Result<Self, Error>
Creates the reader from a SeekRead
implementation.
Makes only the minimum number of reads to check the file header and footer. Fails with an error if an IO error occurs or the file isn’t in OMF 2 format.
sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn open(path: impl AsRef<Path>) -> Result<Self, Error>
Creates a reader by opening the given path.
sourcepub fn set_limits(&mut self, limits: Limits)
pub fn set_limits(&mut self, limits: Limits)
Sets the memory limits.
These limits prevent the reader from consuming excessive system resources, which might allow denial of service attacks with maliciously crafted files. Running without limits is not recommended.
sourcepub fn version(&self) -> [u32; 2]
pub fn version(&self) -> [u32; 2]
Return the version number of the file, which can only be [2, 0]
right now.
sourcepub fn project(&self) -> Result<(Project, Problems), Error>
pub fn project(&self) -> Result<(Project, Problems), Error>
Reads, validates, and returns the root Project
object from the file.
Fails with an error if an IO error occurs, the json_bytes
limit is exceeded, or validation
fails. Validation warnings are returned alongside the project if successful or included
with the errors if not.
sourcepub fn array_compressed_size(
&self,
array: &Array<impl ArrayType>,
) -> Result<u64, Error>
pub fn array_compressed_size( &self, array: &Array<impl ArrayType>, ) -> Result<u64, Error>
Returns the size in bytes of the compressed array.
sourcepub fn array_bytes_reader(
&self,
array: &Array<impl ArrayType>,
) -> Result<SubFile, Error>
pub fn array_bytes_reader( &self, array: &Array<impl ArrayType>, ) -> Result<SubFile, Error>
Returns a sub-file for reading raw bytes from the file.
Fails with an error if the range is invalid. The contents are not checked or validated by this method. The caller must ensure they are valid and safe to use. This function doesn’t check against any limit.