pub struct Parser<E: PropertyAccess> { /* private fields */ }
Expand description
Reads data given by a Read
trait into Ply
components.
In most cases read_ply()
should suffice.
If you need finer control over the read process,
there are methods down to the line/element level.
§Examples
The most common case is probably to read from a file:
// set up a reader, in this case a file.
let path = "example_plys/greg_turk_example1_ok_ascii.ply";
let mut f = std::fs::File::open(path).unwrap();
// create a parser
let p = parser::Parser::<ply::DefaultElement>::new();
// use the parser: read the entire file
let ply = p.read_ply(&mut f);
// Did it work?
assert!(ply.is_ok());
If you need finer control, you can start splitting the read operations down to the line/element level.
In the follwoing case we first read the header, and then continue with the payload. We need to build a Ply our selves.
// set up a reader as before.
// let mut f = ... ;
// We need to wrap our `Read` into something providing `BufRead`
let mut buf_read = std::io::BufReader::new(f);
// create a parser
let p = parser::Parser::<ply::DefaultElement>::new();
// use the parser: read the header
let header = p.read_header(&mut buf_read);
// Did it work?
let header = header.unwrap();
// read the payload
let payload = p.read_payload(&mut buf_read, &header);
// Did it work?
let payload = payload.unwrap();
// May be create your own Ply:
let ply = ply::Ply {
header: header,
payload: payload,
};
println!("Ply: {:#?}", ply);
Implementations§
Source§impl<E: PropertyAccess> Parser<E>
impl<E: PropertyAccess> Parser<E>
Source§impl<E: PropertyAccess> Parser<E>
impl<E: PropertyAccess> Parser<E>
#Header
Sourcepub fn read_header<T: BufRead>(&self, reader: &mut T) -> Result<Header>
pub fn read_header<T: BufRead>(&self, reader: &mut T) -> Result<Header>
Reads header until and inclusive end_header
.
A ply file starts with “ply\n”. The header and the payload are separated by a line end_header\n
.
This method reads all headere elemnts up to end_header
.
pub fn read_header_line(&self, line: &str) -> Result<Line>
Source§impl<E: PropertyAccess> Parser<E>
impl<E: PropertyAccess> Parser<E>
§Payload
Sourcepub fn read_payload<T: BufRead>(
&self,
reader: &mut T,
header: &Header,
) -> Result<Payload<E>>
pub fn read_payload<T: BufRead>( &self, reader: &mut T, header: &Header, ) -> Result<Payload<E>>
Reads payload. Encoding is chosen according to the encoding field in header
.
Sourcepub fn read_payload_for_element<T: BufRead>(
&self,
reader: &mut T,
element_def: &ElementDef,
header: &Header,
) -> Result<Vec<E>>
pub fn read_payload_for_element<T: BufRead>( &self, reader: &mut T, element_def: &ElementDef, header: &Header, ) -> Result<Vec<E>>
Reads entire list of elements from payload. Encoding is chosen according to header
.
Make sure to read the elements in the order as they are defined in the header.
Source§impl<E: PropertyAccess> Parser<E>
impl<E: PropertyAccess> Parser<E>
§Ascii
Sourcepub fn read_ascii_element(
&self,
line: &str,
element_def: &ElementDef,
) -> Result<E>
pub fn read_ascii_element( &self, line: &str, element_def: &ElementDef, ) -> Result<E>
Read a single element. Assume it is encoded in ascii.
Make sure all elements are parsed in the order they are defined in the header.
Source§impl<E: PropertyAccess> Parser<E>
impl<E: PropertyAccess> Parser<E>
§Binary
Sourcepub fn read_big_endian_element<T: Read>(
&self,
reader: &mut T,
element_def: &ElementDef,
) -> Result<E>
pub fn read_big_endian_element<T: Read>( &self, reader: &mut T, element_def: &ElementDef, ) -> Result<E>
Reads a single element as declared in èlement_def. Assumes big endian encoding.
Make sure all elements are parsed in the order they are defined in the header.
Sourcepub fn read_little_endian_element<T: Read>(
&self,
reader: &mut T,
element_def: &ElementDef,
) -> Result<E>
pub fn read_little_endian_element<T: Read>( &self, reader: &mut T, element_def: &ElementDef, ) -> Result<E>
Reads a single element as declared in èlement_def. Assumes big endian encoding.
Make sure all elements are parsed in the order they are defined in the header.