comparison src/th06/std.rs @ 755:fc937d93a57c

Bump nom to version 6, and image to 0.23.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 04 Jan 2021 21:14:02 +0100
parents 13fd434d5d1b
children
comparison
equal deleted inserted replaced
754:a6875f90c141 755:fc937d93a57c
164 } 164 }
165 165
166 fn parse_quad(i: &[u8]) -> IResult<&[u8], Quad> { 166 fn parse_quad(i: &[u8]) -> IResult<&[u8], Quad> {
167 let (i, (unk1, size)) = tuple((le_u16, le_u16))(i)?; 167 let (i, (unk1, size)) = tuple((le_u16, le_u16))(i)?;
168 if unk1 == 0xffff { 168 if unk1 == 0xffff {
169 return Err(Err::Error((i, ErrorKind::Eof))); 169 return Err(Err::Error(nom::error::Error::new(i, ErrorKind::Eof)));
170 } 170 }
171 // TODO: replace this assert with a custom error. 171 // TODO: replace this assert with a custom error.
172 assert_eq!(size, 0x1c); 172 assert_eq!(size, 0x1c);
173 let (i, (anm_script, _, x, y, z, width, height)) = tuple((le_u16, tag(b"\0\0"), le_f32, le_f32, le_f32, le_f32, le_f32))(i)?; 173 let (i, (anm_script, _, x, y, z, width, height)) = tuple((le_u16, tag(b"\0\0"), le_f32, le_f32, le_f32, le_f32, le_f32))(i)?;
174 let quad = Quad { 174 let quad = Quad {
191 } 191 }
192 192
193 fn parse_instance(i: &[u8]) -> IResult<&[u8], Instance> { 193 fn parse_instance(i: &[u8]) -> IResult<&[u8], Instance> {
194 let (i, (id, unknown, x, y, z)) = tuple((le_u16, le_u16, le_f32, le_f32, le_f32))(i)?; 194 let (i, (id, unknown, x, y, z)) = tuple((le_u16, le_u16, le_f32, le_f32, le_f32))(i)?;
195 if id == 0xffff && unknown == 0xffff { 195 if id == 0xffff && unknown == 0xffff {
196 return Err(Err::Error((i, ErrorKind::Eof))); 196 return Err(Err::Error(nom::error::Error::new(i, ErrorKind::Eof)));
197 } 197 }
198 // TODO: replace this assert with a custom error. 198 // TODO: replace this assert with a custom error.
199 assert_eq!(unknown, 0x100); 199 assert_eq!(unknown, 0x100);
200 let instance = Instance { 200 let instance = Instance {
201 id, 201 id,
205 } 205 }
206 206
207 fn parse_instruction(i: &[u8]) -> IResult<&[u8], Call> { 207 fn parse_instruction(i: &[u8]) -> IResult<&[u8], Call> {
208 let (i, (time, opcode, size)) = tuple((le_u32, le_u16, le_u16))(i)?; 208 let (i, (time, opcode, size)) = tuple((le_u32, le_u16, le_u16))(i)?;
209 if time == 0xffffffff && opcode == 0xffff && size == 0xffff { 209 if time == 0xffffffff && opcode == 0xffff && size == 0xffff {
210 return Err(Err::Error((i, ErrorKind::Eof))); 210 return Err(Err::Error(nom::error::Error::new(i, ErrorKind::Eof)));
211 } 211 }
212 // TODO: replace this assert with a custom error. 212 // TODO: replace this assert with a custom error.
213 assert_eq!(size, 12); 213 assert_eq!(size, 12);
214 let (i, instr) = parse_instruction_args(i, opcode)?; 214 let (i, instr) = parse_instruction_args(i, opcode)?;
215 println!("{} {:?}", time, instr); 215 println!("{} {:?}", time, instr);