Conversation
This does not modify the behavior yet, but should better support serializing variable length values.
- add various data types used in the can protocol - add conversion to/from socketcan structs
miDeb
commented
Mar 5, 2026
raffael0
approved these changes
Mar 5, 2026
Member
raffael0
left a comment
There was a problem hiding this comment.
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!
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_SIZEto check size assumptions at compile time.zerocopy-able types automatically implement this trait.Also, a new proc macro is introduced to automatically implement
ByteCodecfor enums or structs that consist of fields that implementByteCodecthemselves.I added a new file
can_data.rswith some special data types that we send over CAN. One example isCanDataValue. It has a custom implementation ofByteCodec, because it does not encode the discriminant. When deserializing, we then don't know what value was originally encoded, so I added a new variantRaw, 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 areCanString(null-terminated ascii string limited to a certain length),PackedCanDataValues(forTelemetryGroupUpdatePayload) andNonNullCanBytes(for thefield_idsinTelemetryGroupDefinitionPayload).I removed the
CanMessageFrametype, and instead now serialize tosocketcan::CanFdFrames from thesocketcancrate. Though that might also live inFerroFlowinstead, I don't know...I also updated the spec to include info about variable length encodings.
Spec diff