Handle special XXXX fields

This commit is contained in:
Tyler Hallada 2021-05-29 16:21:58 -04:00
parent 0e3d127779
commit 9b33136604

View File

@ -275,6 +275,7 @@ fn parse_plugin_header(input: &[u8]) -> IResult<&[u8], PluginHeader> {
let mut author = None; let mut author = None;
let mut description = None; let mut description = None;
let mut masters = vec![]; let mut masters = vec![];
let mut large_size = None;
loop { loop {
let (remaining, field) = parse_field_header(input)?; let (remaining, field) = parse_field_header(input)?;
input = remaining; input = remaining;
@ -299,12 +300,23 @@ fn parse_plugin_header(input: &[u8]) -> IResult<&[u8], PluginHeader> {
input = remaining; input = remaining;
break; break;
} }
"XXXX" => {
let (remaining, size) = le_u32(input)?;
input = remaining;
large_size = Some(size);
}
_ => { _ => {
if let Some(size) = large_size {
let (remaining, _) = take(size)(input)?;
input = remaining;
large_size = None;
} else {
let (remaining, _) = take(field.size)(input)?; let (remaining, _) = take(field.size)(input)?;
input = remaining; input = remaining;
} }
} }
} }
}
Ok(( Ok((
input, input,
PluginHeader { PluginHeader {
@ -378,9 +390,6 @@ fn parse_header(input: &[u8]) -> IResult<&[u8], Header> {
fn parse_field_header(input: &[u8]) -> IResult<&[u8], FieldHeader> { fn parse_field_header(input: &[u8]) -> IResult<&[u8], FieldHeader> {
let (input, field_type) = parse_4char(input)?; let (input, field_type) = parse_4char(input)?;
if field_type == "XXXX" {
todo!()
}
let (input, size) = le_u16(input)?; let (input, size) = le_u16(input)?;
Ok((input, FieldHeader { field_type, size })) Ok((input, FieldHeader { field_type, size }))
} }
@ -399,6 +408,7 @@ fn parse_cell_fields<'a>(input: &'a [u8]) -> IResult<&'a [u8], CellData> {
y: None, y: None,
}; };
let mut input = input; let mut input = input;
let mut large_size = None;
while !input.is_empty() { while !input.is_empty() {
let (remaining, field) = parse_field_header(input)?; let (remaining, field) = parse_field_header(input)?;
input = remaining; input = remaining;
@ -416,12 +426,23 @@ fn parse_cell_fields<'a>(input: &'a [u8]) -> IResult<&'a [u8], CellData> {
let (remaining, _) = take(4usize)(remaining)?; let (remaining, _) = take(4usize)(remaining)?;
input = remaining; input = remaining;
} }
"XXXX" => {
let (remaining, size) = le_u32(input)?;
input = remaining;
large_size = Some(size);
}
_ => { _ => {
if let Some(size) = large_size {
let (remaining, _) = take(size)(input)?;
input = remaining;
large_size = None;
} else {
let (remaining, _) = take(field.size)(input)?; let (remaining, _) = take(field.size)(input)?;
input = remaining; input = remaining;
} }
} }
} }
}
Ok((input, cell_data)) Ok((input, cell_data))
} }