Skip to content

variable payload length#9

Merged
miDeb merged 16 commits intomainfrom
feat/variable-length-can
Mar 5, 2026
Merged

variable payload length#9
miDeb merged 16 commits intomainfrom
feat/variable-length-can

Conversation

@miDeb
Copy link
Member

@miDeb miDeb commented Mar 5, 2026

This PR first introduces a new trait ByteCodec (open to other naming suggestions).
It allows to serialize to a variable number of bytes, as well as deserialize from an arbitrary number of bytes. It also contains a MAX_SERIALIZED_SIZE to check size assumptions at compile time. zerocopy-able types automatically implement this trait.
Also, a new proc macro is introduced to automatically implement ByteCodec for enums or structs that consist of fields that implement ByteCodec themselves.

I added a new file can_data.rs with some special data types that we send over CAN. One example is CanDataValue. It has a custom implementation of ByteCodec, because it does not encode the discriminant. When deserializing, we then don't know what value was originally encoded, so I added a new variant Raw, that is created when deserializing. It can then be converted to a regular variant by supplying the actual data type (convert_from_raw). Other types with custom serialization/deserialization I added are CanString (null-terminated ascii string limited to a certain length), PackedCanDataValues (for TelemetryGroupUpdatePayload) and NonNullCanBytes (for the field_ids in TelemetryGroupDefinitionPayload).

I removed the CanMessageFrame type, and instead now serialize to socketcan::CanFdFrames from the socketcan crate. Though that might also live in FerroFlow instead, I don't know...

I also updated the spec to include info about variable length encodings.

Spec diff

Copy link
Member

@raffael0 raffael0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really great! Thank you for the work.
This will really simplify the implementation.
There were some small things where I think we could improve the performance, but I don't want to do any more bike shedding and I think it'll be fine for now (At least until we run performance tests).

Feel free to merge!

@miDeb miDeb merged commit a3c3da0 into main Mar 5, 2026
1 check passed
@miDeb miDeb mentioned this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants