Deserializing Binary Data Files in Rust
adventures.michaelfbryan.com
Deserializing Binary Data Files in Rust
1–10 of 23 posts
Re: Deserializing Binary Data Files in Rust
#2Re: Deserializing Binary Data Files in Rust
#3I think c struct is missing alignment attribute? This idea has been explored in flatbuffers, capnproto and probably others.
The one possible issue is that reading padding is UB (i think). But here there should be no padding: the struct is a pair number of bytes (alignment 1) and a word (alignment 2), which us aligned due to the previous, and the struct is if alignment 2.
Re: Deserializing Binary Data Files in Rust
#4I think c struct is missing alignment attribute? This idea has been explored in flatbuffers, capnproto and probably others.
C structs are generally assumed to be laid out in the order defined with proper padding automatically inserted (as most platforms at best dislike unaligned accesses). Alignment information should only be necessary if you want to pack the structure or need to apply wider than standard alignment (e.g. need to align a 32 or 64b type to 128 bytes). The one possible issue is that reading padding is UB (i think). But here…
Re: Deserializing Binary Data Files in Rust
#5Earlier quoted context omitted.
C structs are generally assumed to be laid out in the order defined with proper padding automatically inserted (as most platforms at best dislike unaligned accesses). Alignment information should only be necessary if you want to pack the structure or need to apply wider than standard alignment (e.g. need to align a 32 or 64b type to 128 bytes). The one possible issue is that reading padding is UB (i think). But here…
yeah C will be order defined in code, rust will reorder to save space unless you attribute it not to. interesting trivia a blind guy wrote the reordering code. if anyone knows his name please post.
Re: Deserializing Binary Data Files in Rust
#6I think c struct is missing alignment attribute? This idea has been explored in flatbuffers, capnproto and probably others.
C structs are generally assumed to be laid out in the order defined with proper padding automatically inserted (as most platforms at best dislike unaligned accesses). Alignment information should only be necessary if you want to pack the structure or need to apply wider than standard alignment (e.g. need to align a 32 or 64b type to 128 bytes). The one possible issue is that reading padding is UB (i think). But here…
Re: Deserializing Binary Data Files in Rust
#7From their website:
> Kaitai Struct is a declarative language used to describe various binary data structures, laid out in files or in memory: i.e. binary file formats, network stream packet formats, etc.
They even have a Rust interface: https://github.com/kaitai-io/kaitai_struct_rust_runtime
Re: Deserializing Binary Data Files in Rust
#8Earlier quoted context omitted.
yeah C will be order defined in code, rust will reorder to save space unless you attribute it not to. interesting trivia a blind guy wrote the reordering code. if anyone knows his name please post.
The rust structure is defined as repr(C) so there is no reordering.
Re: Deserializing Binary Data Files in Rust
#9Re: Deserializing Binary Data Files in Rust
#10Earlier quoted context omitted.
C structs are generally assumed to be laid out in the order defined with proper padding automatically inserted (as most platforms at best dislike unaligned accesses). Alignment information should only be necessary if you want to pack the structure or need to apply wider than standard alignment (e.g. need to align a 32 or 64b type to 128 bytes). The one possible issue is that reading padding is UB (i think). But here…
yeah C will be order defined in code, rust will reorder to save space unless you attribute it not to. interesting trivia a blind guy wrote the reordering code. if anyone knows his name please post.