deku_string
is an utility crate for Deku that provides convenient support
for serializing and deserializing String and Vec in a variety of binary formats.
It handles UTF-8, UTF-16 and UTF-32 encoded strings and is suitable for parsing complex layouts.
- String support UTF-8, UTF-16 and UTF-32 support.
- Multiple layout formats, such as .Net, Pascal and zero-ended.
- Little and Big Endian support.
- Dynamic read and write without additional temporary structs and operations.
- No need to specify custom reader and writer.
- Compatible with Deku's derive macros and custom readers/writers.
- Supports serde via
serde
feature anddefmt
for embedded programming.
- Fixed-length strings
- With or without zero-termination
- Pascal-style strings
- Length-prefixed strings having length size
u8
,u16
, oru32
- Length-prefixed strings having length size
- .NET length prefix
- Length-prefixed strings having length size
u32
7-bit encoded (like in .NET)
- Length-prefixed strings having length size
- C-style strings
- Zero-terminated strings
#[derive(Default, Debug, Clone, PartialEq, PartialOrd, deku::DekuRead, deku::DekuWrite)]
#[deku(endian = "little")]
struct SampleModel {
#[deku(ctx = "Encoding::Utf8, StringLayout::fixed_length(10)")]
fixed_value: StringDeku,
// Vector of strings, each of them have their own layout.
#[deku(ctx = "VecLayout::LengthPrefix(Size::U32_7Bit), (Encoding::Utf8, StringLayout::LengthPrefix(Size::U8))")]
vec_of_strings: VecDeku<StringDeku>
// Read u8 into vector to the end.
#[deku(ctx = "VecLayout::FixedSize(10)")]
vec: VecDeku<u8>,
}
Contributions are welcome!
Whether you're fixing a bug, improving performance, adding support for new string formats, or just refining docs — your pull requests and suggestions are greatly appreciated.