samcrow / canadensis

A Rust implementation of Cyphal
Apache License 2.0
44 stars 5 forks source link

Make zero-copy generated types unpacked when possible #25

Open samcrow opened 1 year ago

samcrow commented 1 year ago

Some fixed-size struct DSDL types produce generated Rust code with zero-copy serialization and deserialization. Note is one example.

These types are marked #[repr(C, packed)] to ensure they will not have padding, so their memory layout will match the DSDL-specified layout.

Packed structs are inconvenient because we can't use derives to implement traits and can't safely create references to their fields. Some of these types have no padding anyway, so they don't need to be packed.

The code generator should identify those types and not mark them as packed.

Caution: Memory layout and padding may be different for different platforms. Currently, there's only one version of canadensis_data_types for all little-endian platforms.