8000 Releases Β· sharksforarms/deku Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Releases: sharksforarms/deku

v0.19.0

25 Apr 18:55
Compare
Choose a tag to compare

Features

Added bit_order (#483)

After much development, bit_order is now a supported attribute! Msb is still the default bit-order for all operations,
but if you need Lsb ordering, deku now has you covered.

For example, the following is now possible:

# #[derive(Debug, DekuRead, DekuWrite, PartialEq)]
#[deku(bit_order = "lsb")] // <--
pub struct SquashfsV3 {
    #[deku(bits = "4")]
    inode_type: u8,
    #[deku(bits = "12")]
    mode: u16,
    uid: u8,
    guid: u8,
    mtime: u32,
    inode_number: u32,
}
let data: &[u8] = &[
//       inode_type
//     β•­-----------
//     |
//     |    mode
//    β•­+--------   ...and so on
//    ||    ||
//    vv    vv
    0x31, 0x12, 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
];

If you were using our internal reader the following changed. As well as the leftover field now containing ordering.

- reader.read_bytes(exact.0, &mut bytes)?;
+ reader.read_bytes(exact.0, &mut bytes, Order::Lsb0)?;

Added bytes ctx for CString (#497)

#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
pub struct Data {
    len: u8,
    #[deku(bytes = "*len as usize")]
    s: CString,
}

Changed id_pat (#540)

The id_pat attribute has been restored to the behavior of 0.16.0, removing the seek and re-read.

Allow token streams for bytes attribute (#489)

# #[derive(Debug, PartialEq, DekuRead, DekuWrite)]
struct DekuTest {
    field_a_size: u8,
    #[deku(bytes = "*field_a_size as usize")]
    field_a: u32,
}

Updates

  • Arc support by @vhdirk (#522)
  • Update no-std-io2 to 0.9.0 and Updated MSRV to 1.81 (#529)
  • Add field support for magic attribute (#503)
  • Add NoSeek type for unseekable Read + Write impls (#487)
  • Add performance specializations for count attribute + Vec<u8>(#481)
  • Reader may now take ownership of Read + Seek type. Thanks @wgreenburg (#521).

Fixes

  • Fix pad_* attributes in no_std (#478)
  • Fix bug with id_pat and read_bytes_const (#479)
  • Several fixes for scope and imports in proc-macros, thanks @Serial-ATA (#541, #538, #539)

v0.18.0

07 Sep 15:23
Compare
Choose a tag to compare

Usability

  • Reading now requires Seek. Attributes such as seek_from_start, seek_from_current, seek_from_end, and seek_rewind were added to be able to control the position of the reader before reading a field (#360)
  • Support added for unit structs (#450)
  • to_slice was added to write an to a slice (#461)

Performance

  • The use of bits parsing is now an optional feature. If bit-level parsing is not useful for your application, you can disable it to get some performance benefits. (#446)
  • Performance of read_all was improved (#441)

Enum improvements

  • Added id_endian attribute to specify the endianness of id (#476)
  • Support for bool literals in enum id attribute (#472)
  • id_pat attribute was re-introduced (#454)

v0.17.0

24 May 03:29
Compare
Choose a tag to compare

Changes

  • Bumped MSRV to 1.71 (#438)
  • Add DekuWrite impl for [T] (#416)
  • Add no-assert-string feature to remove panic string on failed assertion (#405)
  • Add read_all attribute to read until reader.end() (#387)
  • Changed edition to 2021 (#389)
  • Refactored logging feature with massive usability increases (#352), (#355)
  • Bumped the syn library to 2.0, which required replacing type for Enums with id_type (#386)
 #[derive(PartialEq, Debug, DekuRead, DekuWrite)]
-#[deku(type = "u8")]
+#[deku(id_type = "u8")]
 enum DekuTest {
     #[deku(id_pat = "_")]
     VariantC((u8, u8)),
 }

Updated Reader API

  • Changed API of reading to use io::Read, bringing massive performance and usability improvements (#352)
  • Changed the trait DekuRead to DekuReader

For example:

use std::io::{Seek, SeekFrom, Read};
use std::fs::File;
use deku::prelude::*;

#[derive(Debug, DekuRead, DekuWrite, PartialEq, Eq, Clone, Hash)]
#[deku(endian = "big")]
struct EcHdr {
    magic: [u8; 4],
    version: u8,
    padding1: [u8; 3],
}

let mut file = File::options().read(true).open("file").unwrap();
let ec = EcHdr::from_reader((&mut file, 0)).unwrap();
  • The more internal (with context) read(..) was replaced with from_reader_with_ctx(..).
    With the switch to internal streaming, the variables deku::input, deku::input_bits, and deku::rest are now not possible and were removed.
    deku::reader is a replacement for some of the functionality.
    See examples/deku_input.rs for a new example of caching all reads.

Old:

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
struct DekuTest {
    field_a: u8,

    #[deku(
        reader = "bit_flipper_read(*field_a, deku::rest, BitSize(8))",
    )]
    field_b: u8,
}

fn custom_read(
    field_a: u8,
    rest: &BitSlice<u8, Msb0>,
    bit_size: BitSize,
) -> Result<(&BitSlice<u8, Msb0>, u8), DekuError> {

    // read field_b, calling original func
    let (rest, value) = u8::read(rest, bit_size)?;

    Ok((rest, value))
}

New:

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
struct DekuTest {
    field_a: u8,

    #[deku(
        reader = "bit_flipper_read(*field_a, deku::reader, BitSize(8))",
    )]
    field_b: u8,
}

fn custom_read<R: std::io::Read>(
    field_a: u8,
    reader: &mut Reader<R>,
    bit_size: BitSize,
) -> Result<u8, DekuError> {

    // read field_b, calling original func
    let value = u8::from_reader_with_ctx(reader, bit_size)?;

    Ok(value)
}
  • With the addition of using Read, containing a byte slice with a reference is not supported:

Old

#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
struct TestStruct<'a> {
    bytes: u8,

    #[deku(bytes_read = "bytes")]
    data: &'a [u8],
}

New

#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
struct TestStruct {
    bytes: u8,

    #[deku(bytes_read = "bytes")]
    data: Vec<u8>,
}
  • id_pat is now required to be the same type as stored id.
    This also disallows using tuples for storing the id:

Old:

#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
#[deku(id_type = "u8")]
enum DekuTest {
    #[deku(id_pat = "_")]
    VariantC((u8, u8)),
}

New:

#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
#[deku(id_type = "u8")]
enum DekuTest {
    #[deku(id_pat = "_")]
    VariantC {
        id: u8,
        other: u8,
    },
}
  • The feature const_generics was removed and is enabled by default.

Updated Writer API

  • Changed API of writing to use io::Write, bringing massive performance and usability improvements (#355)
  • Changed the trait DekuWrite to DekuWriter
  • The more internal (with context) write(..) was replaced with to_writer(..).
    With the switch to internal streaming, the variables deku::output are now not possible and were removed. deku::writer is a replacement for some of the functionality.

Old:

fn bit_flipper_write(
    field_a: u8,
    field_b: u8,
    output: &mut BitVec<u8, Msb0>,
    bit_size: BitSize,
) -> Result<(), DekuError> {
    // Access to previously written fields
    println!("field_a = 0x{:X}", field_a);

    // value of field_b
    println!("field_b = 0x{:X}", field_b);

    // Size of the current field
    println!("bit_size: {:?}", bit_size);

    // flip the bits on value if field_a is 0x01
    let value = if field_a == 0x01 { !field_b } else { field_b };

    value.write(output, bit_size)
}

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
struct DekuTest {
    field_a: u8,

    #[deku(
        writer = "bit_flipper_write(*field_a, *field_b, deku::output, BitSize(8))"
    )]
    field_b: u8,
}

New:

fn bit_flipper_write<W: Write>(
    field_a: u8,
    field_b: u8,
    writer: &mut Writer<W>,
    bit_size: BitSize,
) -> Result<(), DekuError> {
    // Access to previously written fields
    println!("field_a = 0x{:X}", field_a);

    // value of field_b
    println!("field_b = 0x{:X}", field_b);

    // Size of the current field
    println!("bit_size: {:?}", bit_size);

    // flip the bits on value if field_a is 0x01
    let value = if field_a == 0x01 { !field_b } else { field_b };

    value.to_writer(writer, bit_size)
}

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
struct DekuTest {
    field_a: u8,

    #[deku(
        writer = "bit_flipper_write(*field_a, *field_b, deku::writer, BitSize(8))"
    )]
    field_b: u8,
}
  • Added DekuError::Write to denote io::Write errors

Bug fix

  • Fix error for invalid deku_id generation on generic enum (#411)
0