pub struct Parser<R> { /* private fields */ }
Expand description
Pull parser for FBX 7.4 binary or compatible later versions.
Implementations§
Source§impl<R: Read> Parser<R>
impl<R: Read> Parser<R>
Sourcepub const PARSER_VERSION: ParserVersion = ParserVersion::V7400
pub const PARSER_VERSION: ParserVersion = ParserVersion::V7400
Parser version.
Sourcepub fn from_reader(header: FbxHeader, reader: R) -> Result<Self>
pub fn from_reader(header: FbxHeader, reader: R) -> Result<Self>
Creates a new Parser
from the given reader.
Returns an error if the given FBX version in unsupported.
Sourcepub fn from_seekable_reader(header: FbxHeader, reader: R) -> Result<Self>where
R: Seek,
pub fn from_seekable_reader(header: FbxHeader, reader: R) -> Result<Self>where
R: Seek,
Creates a new Parser
from the given seekable reader.
Returns an error if the given FBX version in unsupported.
Sourcepub fn set_warning_handler<F>(&mut self, warning_handler: F)
pub fn set_warning_handler<F>(&mut self, warning_handler: F)
Sets the warning handler.
The warning handler will receive warnings and their syntactic positions each time the warnings happen.
If the handler returned Ok(())
, the warning is considered non-critical
and parsing can be continued.
If the handler returned Err(_)
, the warning is considered critical,
and the parsing cannot be continued.
§Examples
let mut parser = fbxcel::pull_parser::v7400::Parser::from_reader(header, reader)
.expect("Failed to create parser");
parser.set_warning_handler(|warning, pos| {
// Print warning.
eprintln!("WARNING: {} (pos={:?})", warning, pos);
// To ignore the warning and continue processing, return `Ok(())`.
// To treat the given warning as a critical error, return
// `Err(warning.into())`.
Ok(())
});
Sourcepub fn fbx_version(&self) -> FbxVersion
pub fn fbx_version(&self) -> FbxVersion
Returns FBX version.
Sourcepub fn current_node_name(&self) -> &str
pub fn current_node_name(&self) -> &str
Sourcepub fn current_depth(&self) -> usize
pub fn current_depth(&self) -> usize
Returns current node depth.
Implicit root node is considered to be depth 0.
Sourcepub fn next_event(&mut self) -> Result<Event<'_, R>>
pub fn next_event(&mut self) -> Result<Event<'_, R>>
Returns next event if successfully read.
You should not call next_event()
if a parser functionality has been
already failed and returned error.
If you call next_event()
with failed parser, error created from
OperationError::AlreadyAborted
will be returned.
Sourcepub fn skip_current_node(&mut self) -> Result<()>
pub fn skip_current_node(&mut self) -> Result<()>
Ignores events until the current node closes.
This discards parser events until the EndNode
event for the current
node is read.
The last EndNode
(for the current node) is also discarded.
This method seeks to the node end position without any additional parsing, since the parser already knows the node end position. Because of this, some errors can be overlooked, or detected at the different position from the true error position.
To detect errors correctly, you should use next_event
manually.
See an example to how to do this.
§Panics
Panics if there are no open nodes, i.e. when current_depth()
returns 0.
§Examples
let mut parser = fbxcel::pull_parser::v7400::Parser::from_reader(header, reader)
.expect("Failed to create parser");
// Do something here.
// Something done.
let depth = parser.current_depth();
if depth > 0 {
parser.skip_current_node().expect("Failed to skip current node");
assert_eq!(parser.current_depth(), depth - 1);
}
parser.skip_current_node()
is almost same as the code below, except
for error handling.
fn skip_current_node<R: std::io::Read>(parser: &mut Parser<R>) -> Result<()> {
loop {
match parser.next_event()? {
Event::StartNode(_) => skip_current_node(parser)?,
Event::EndNode => return Ok(()),
Event::EndFbx(_) => panic!("Attempt to skip implicit top-level node"),
}
}
}
Sourcepub fn position(&self) -> SyntacticPosition
pub fn position(&self) -> SyntacticPosition
Returns the syntactic position of the current node.
Note that this allocates memory.
Sourcepub fn is_used(&self) -> bool
pub fn is_used(&self) -> bool
Returns whether the parser is already used or brand-new.
Returns true
if the parser emitted some events in the past, returns
false
if the parser have not emitted any events.
§Examples
let mut parser = fbxcel::pull_parser::v7400::Parser::from_reader(header, reader)
.expect("Failed to create parser");
assert!(!parser.is_used());
parser.set_warning_handler(|warning, pos| {
// Print warning.
eprintln!("WARNING: {} (pos={:?})", warning, pos);
// To ignore the warning and continue processing, return `Ok(())`.
// To treat the given warning as a critical error, return
// `Err(warning.into())`.
Ok(())
});
assert!(!parser.is_used(), "Parser emitted no events yet");
let _ = parser.next_event();
assert!(parser.is_used(), "Parser emitted an event");