1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-04 10:34:11 +02:00

packet parsers

This commit is contained in:
Robin Appelman 2019-02-25 23:20:51 +01:00
commit b41bb56822
19 changed files with 626 additions and 64 deletions

View file

@ -1,10 +1,39 @@
use crate::{Parse, ParseError, ParserState, Result, Stream};
pub struct Vector {
pub x: f32,
pub y: f32,
pub z: f32,
}
impl Parse<'_> for Vector {
fn parse(stream: &mut Stream, _state: &ParserState) -> Result<Self> {
Ok(Vector {
x: stream.read_float()?,
y: stream.read_float()?,
z: stream.read_float()?,
})
}
fn skip(stream: &mut Stream) -> Result<()> {
stream.skip(32 * 3).map_err(ParseError::from)
}
}
pub struct VectorXY {
pub x: f32,
pub y: f32,
}
impl Parse<'_> for VectorXY {
fn parse(stream: &mut Stream, _state: &ParserState) -> Result<Self> {
Ok(VectorXY {
x: stream.read_float()?,
y: stream.read_float()?,
})
}
fn skip(stream: &mut Stream) -> Result<()> {
stream.skip(32 * 2).map_err(ParseError::from)
}
}