Remove panic!
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f393fdacd2
commit
72adbdb624
|
@ -1,6 +1,7 @@
|
|||
use nom::bytes::streaming::{tag, take};
|
||||
use nom::error::{Error, ErrorKind};
|
||||
use nom::number::streaming::{le_u16, le_u24, le_u32, le_u8};
|
||||
use nom::IResult;
|
||||
use nom::{Err, IResult};
|
||||
|
||||
#[derive(Eq, Debug, PartialEq)]
|
||||
pub enum Codec {
|
||||
|
@ -147,7 +148,7 @@ fn parse_sound_data(input: &[u8]) -> IResult<&[u8], BlockType> {
|
|||
4 => Codec::Pcm16BitSigned,
|
||||
5 => Codec::Alaw,
|
||||
6 => Codec::Ulaw,
|
||||
_ => panic!("Invalid sound format"),
|
||||
_ => return Err(Err::Error(Error::new(input, ErrorKind::Alt))),
|
||||
};
|
||||
let (input, data) = take(block_size - 2)(input)?;
|
||||
Ok((
|
||||
|
@ -221,7 +222,7 @@ fn parse_extra_information(input: &[u8]) -> IResult<&[u8], BlockType> {
|
|||
4 => Codec::Pcm16BitSigned,
|
||||
5 => Codec::Alaw,
|
||||
6 => Codec::Ulaw,
|
||||
_ => panic!("Invalid sound format"),
|
||||
_ => return Err(Err::Error(Error::new(input, ErrorKind::Alt))),
|
||||
};
|
||||
let sample_rate: u32 =
|
||||
256000000_u32 / ((channels as u32 + 1) * (65536 - frequency_divisor as u32));
|
||||
|
@ -252,7 +253,7 @@ fn parse_sound_data_new(input: &[u8]) -> IResult<&[u8], BlockType> {
|
|||
5 => Codec::Alaw,
|
||||
6 => Codec::Ulaw,
|
||||
0x0200 => Codec::Adpcm4to16,
|
||||
_ => panic!("Invalid sound format"),
|
||||
_ => return Err(Err::Error(Error::new(input, ErrorKind::Alt))),
|
||||
};
|
||||
Ok((
|
||||
input,
|
||||
|
@ -280,7 +281,7 @@ pub fn parse_block(input: &[u8]) -> IResult<&[u8], BlockType> {
|
|||
7 => Ok((input, BlockType::RepeatEnd)),
|
||||
8 => parse_extra_information(input),
|
||||
9 => parse_sound_data_new(input),
|
||||
_ => panic!("Invalid block type - {}", block_type),
|
||||
_ => Err(Err::Error(Error::new(input, ErrorKind::Alt))),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,7 +292,7 @@ pub fn parse_voc(input: &[u8]) -> IResult<&[u8], Voc> {
|
|||
let (input, version_major) = le_u8(input)?;
|
||||
let (input, checksum) = le_u16(input)?;
|
||||
|
||||
// Calculate checksum from version
|
||||
// Calculate checksum
|
||||
let checksum2 = (!i16::from_le_bytes([version_minor, version_major]) + 0x1234) as u16;
|
||||
let valid = checksum == checksum2;
|
||||
|
||||
|
@ -304,7 +305,7 @@ pub fn parse_voc(input: &[u8]) -> IResult<&[u8], Voc> {
|
|||
blocks.push(block);
|
||||
remaining_input = input;
|
||||
}
|
||||
Err(nom::Err::Incomplete(_)) => {
|
||||
Err(Err::Incomplete(_)) => {
|
||||
break;
|
||||
}
|
||||
Err(err) => {
|
||||
|
|
Loading…
Reference in New Issue