-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add types and de/encoding for SCMP messages #101
Conversation
|
a0a7b57
to
9dd2430
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Markus, looking good.
One thing that wasn't clear is why the Other* enum variants start from 0.
9dd2430
to
ec245bd
Compare
ec245bd
to
76d4587
Compare
Added some basic conversion tests. |
76d4587
to
32017f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Markus,
Thanks for all of your work on this. I made an initial pass, but still need to go through the details of each of the messages. In the mean time, I figured I could already let you have my thoughts so far. I feel that most of what you have here is good, my main issue being with your usage of traits (here comes object-safety).
First, since traits need to be imported to use the associated methods, having the methods spread over too many traits can be uncomfortable to use. Currently there are traits for the basic methods, one with the checksum methods, and ones for information and error messages, which do not follow the object relationship:
ScmpMessageBasicData
->Sized
ScmpMessageEncodeDecode
->ScmpMessageBasicData
ScmpErrorMessage
ScmpInformationalMessage
To use most functionality, one would need to import at least n1, n3, or n1 and n4, and additionally n2 if one needs information about the checksum. Perhaps the following structure would be more usable:
ScmpMessageBase
ScmpMessageEncodeDecode
->ScmpMessageBase
+Sized
ScmpErrorMessage
->ScmpMessageBase
ScmpInformationalMessage
->ScmpMessageBase
This would allow importing only n3 or n4 depending on the use-case. n2 could also be rolled into n1, since all ScmpMessages would implement it. But I imagine that logic may be used more rarely, so perhaps that's not necessary.
Second, it would be nice if n1, n3, and n4 could all be object safe. This would allow creating a Box<dyn ScmpMessageBase>
where one does not care about the type of message being passed around. The current trait forces ScmpMessageBasicData
to only be used with static dispatch. Doing this would require removing the associated const MESSAGE_TYPE
, which could be placed on the the actual struct and then used in the implementation of the trait.
Rolling n2 into n1, would complicate the above, since that uses generic functions and returns Self
in one of its methods.
Finally, ScmpMessageRaw
, despite technically being a ScmpMessage, does not implement any of the traits. I would have expected it to implement n1 and n2.
@jpcsmith I've reorganized the traits in 0c2bc28. I made Let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Markus, thanks for the changes. Looks good to go.
0c2bc28
to
ee5c0a0
Compare
Contributes to #54
Closes #112