follow masque interface
This commit is contained in:
parent
22040d9432
commit
d3bf15f47a
1 changed files with 54 additions and 54 deletions
|
|
@ -24,7 +24,7 @@ pub struct RecordHeader {
|
|||
}
|
||||
|
||||
impl RecordHeader {
|
||||
pub fn read(input: &[u8]) -> IResult<RecordHeader> {
|
||||
pub fn read(input: &[u8]) -> IResult<'_, RecordHeader> {
|
||||
let (input, size) = parse_u16(input)?;
|
||||
let (input, tag) = parse_u16(input)?;
|
||||
Ok((input, RecordHeader{tag, data_size:size - 4}))
|
||||
|
|
@ -50,7 +50,7 @@ pub trait RecordData {
|
|||
type InData : ?Sized;
|
||||
type ByteData : AsRef<[u8]>;
|
||||
|
||||
fn read(input: &[u8], size: u16) -> IResult<Self::BareData<'_>>;
|
||||
fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>>;
|
||||
fn pack_into(buf: &mut [u8], data: &Self::InData);
|
||||
//fn size(data: &Self::BareData<'_>) -> u16;
|
||||
fn pack(data: &Self::InData) -> Self::ByteData;
|
||||
|
|
@ -72,7 +72,7 @@ pub trait Record<RData: RecordData> {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_header(input: &[u8]) -> IResult<RecordHeader> {
|
||||
fn read_header(input: &[u8]) -> IResult<'_, RecordHeader> {
|
||||
RecordHeader::read(input)
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ pub trait Record<RData: RecordData> {
|
|||
RecordHeader{tag: Self::tag(), data_size}.write(ww)
|
||||
}
|
||||
|
||||
fn read_data(input: &[u8], size: u16) -> IResult<RData::BareData<'_>> {
|
||||
fn read_data(input: &[u8], size: u16) -> IResult<'_, RData::BareData<'_>> {
|
||||
RData::read(input, size)
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ pub trait Record<RData: RecordData> {
|
|||
/// True if the record was encountered and skipped.
|
||||
/// False if the end of the library was reached.
|
||||
///
|
||||
fn skip_past(input: &[u8]) -> IResult<bool> {
|
||||
fn skip_past(input: &[u8]) -> IResult<'_, bool> {
|
||||
let original_input = input;
|
||||
let (mut input, mut header) = RecordHeader::read(input)?;
|
||||
while header.tag != Self::tag() {
|
||||
|
|
@ -109,7 +109,7 @@ pub trait Record<RData: RecordData> {
|
|||
Ok((input, true))
|
||||
}
|
||||
|
||||
fn skip_and_read(input: &[u8]) -> IResult<RData::BareData<'_>> {
|
||||
fn skip_and_read(input: &[u8]) -> IResult<'_, RData::BareData<'_>> {
|
||||
let (mut input, mut header) = RecordHeader::read(input)?;
|
||||
while header.tag != Self::tag() {
|
||||
(input, _) = take_bytes(input, header.data_size)?;
|
||||
|
|
@ -119,7 +119,7 @@ pub trait Record<RData: RecordData> {
|
|||
Ok((input, data))
|
||||
}
|
||||
|
||||
fn expect_header(input: &[u8]) -> IResult<u16> {
|
||||
fn expect_header(input: &[u8]) -> IResult<'_, u16> {
|
||||
let (input, header) = RecordHeader::read(input)?;
|
||||
if header.tag != Self::tag() {
|
||||
fail(input, format!("Unexpected record! Got tag 0x{:04x}, expected 0x{:04x}", header.tag, Self::tag()))
|
||||
|
|
@ -128,7 +128,7 @@ pub trait Record<RData: RecordData> {
|
|||
}
|
||||
}
|
||||
|
||||
fn read(input: &[u8]) -> IResult<RData::BareData<'_>> {
|
||||
fn read(input: &[u8]) -> IResult<'_, RData::BareData<'_>> {
|
||||
let (input, size) = Self::expect_header(input)?;
|
||||
Self::check_size(size).unwrap();
|
||||
let (input, data) = Self::read_data(input, size)?;
|
||||
|
|
@ -152,7 +152,7 @@ impl RecordData for BitArray {
|
|||
type InData = [bool; 16];
|
||||
type ByteData = [u8; 2];
|
||||
|
||||
fn read(input: &[u8], size: u16) -> IResult<Self::BareData<'_>> {
|
||||
fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> {
|
||||
assert!(size == 2);
|
||||
parse_bitarray(input)
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ impl RecordData for Int2 {
|
|||
type InData = i16;
|
||||
type ByteData = [u8; 2];
|
||||
|
||||
fn read(input: &[u8], size: u16) -> IResult<Self::BareData<'_>> {
|
||||
fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> {
|
||||
assert!(size == 2);
|
||||
parse_int2(input)
|
||||
}
|
||||
|
|
@ -197,7 +197,7 @@ impl RecordData for Int4 {
|
|||
type InData = i32;
|
||||
type ByteData = [u8; 4];
|
||||
|
||||
fn read(input: &[u8], size: u16) -> IResult<Self::BareData<'_>> {
|
||||
fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> {
|
||||
assert!(size == 4);
|
||||
parse_int4(input)
|
||||
}
|
||||
|
|
@ -220,7 +220,7 @@ impl RecordData for Int2Array {
|
|||
type InData = [i16];
|
||||
type ByteData = Vec<u8>;
|
||||
|
||||
fn read(input: &[u8], size: u16) -> IResult<Self::BareData<'_>> {
|
||||
fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> {
|
||||
assert!(size % 2 == 0, "Record must contain an integer quantity of integers");
|
||||
//let mut input = input;
|
||||
let (input, bytes) = take_bytes(input, size)?;
|
||||
|
|
@ -261,7 +261,7 @@ impl RecordData for Int4Array {
|
|||
type InData = [i32];
|
||||
type ByteData = Vec<u8>;
|
||||
|
||||
fn read(input: &[u8], size: u16) -> IResult<Self::BareData<'_>> {
|
||||
fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> {
|
||||
assert!(size % 4 == 0, "Record must contain an integer quantity of integers");
|
||||
//let mut input = input;
|
||||
let (input, bytes) = take_bytes(input, size)?;
|
||||
|
|
@ -302,7 +302,7 @@ impl RecordData for Real8 {
|
|||
type InData = f64;
|
||||
type ByteData = [u8; 8];
|
||||
|
||||
fn read(input: &[u8], size: u16) -> IResult<Self::BareData<'_>> {
|
||||
fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> {
|
||||
assert!(size == 8);
|
||||
parse_real8(input)
|
||||
}
|
||||
|
|
@ -324,7 +324,7 @@ impl RecordData for Real8Pair {
|
|||
type InData = (f64, f64);
|
||||
type ByteData = [u8; 2 * 8];
|
||||
|
||||
fn read(input: &[u8], size: u16) -> IResult<Self::BareData<'_>> {
|
||||
fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> {
|
||||
assert!(size == 2 * 8);
|
||||
let (input, data0) = parse_real8(input)?;
|
||||
let (input, data1) = parse_real8(input)?;
|
||||
|
|
@ -354,7 +354,7 @@ impl RecordData for ASCII {
|
|||
type InData = [u8];
|
||||
type ByteData = Vec<u8>;
|
||||
|
||||
fn read(input: &[u8], size: u16) -> IResult<Self::BareData<'_>> {
|
||||
fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> {
|
||||
parse_ascii(input, size)
|
||||
}
|
||||
|
||||
|
|
@ -376,7 +376,7 @@ impl RecordData for DateTimePair {
|
|||
type InData = [[i16; 6]; 2];
|
||||
type ByteData = [u8; 2 * 6 * 2];
|
||||
|
||||
fn read(input: &[u8], size: u16) -> IResult<Self::BareData<'_>> {
|
||||
fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> {
|
||||
assert!(size == 2 * 6 * 2);
|
||||
let (input, data0) = parse_datetime(input)?;
|
||||
let (input, data1) = parse_datetime(input)?;
|
||||
|
|
@ -406,7 +406,7 @@ impl RecordData for Empty {
|
|||
type InData = ();
|
||||
type ByteData = [u8; 0];
|
||||
|
||||
fn read(input: &[u8], size: u16) -> IResult<Self::BareData<'_>> {
|
||||
fn read(input: &[u8], size: u16) -> IResult<'_, Self::BareData<'_>> {
|
||||
assert!(size == 0);
|
||||
Ok((input, ()))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue