Skip to content
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

Add serde derive macros where applicable #43

Merged
merged 1 commit into from
Dec 18, 2022

Conversation

daviessm
Copy link

I had a requirement to serialize packets. What would you think of adding serde support to the package, behind a feature flag?

@JulianSchmid
Copy link
Owner

JulianSchmid commented Dec 17, 2022

Hi @daviessm ,

I like it, but I would as you proposed (and did) put it behind a non default feature flag.

Greets
Julian

@@ -21,6 +21,7 @@ pub const IPV6_MAX_NUM_HEADER_EXTENSIONS: usize = 12;
/// * Host Identity Protocol
/// * Shim6 Protocol
#[derive(Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Copy link
Owner

Choose a reason for hiding this comment

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

I think a manual implementation of Serialize & Deserialize is needed for Ipv6RawExtensionHeader so that only the part of the payload buffer that is actually filled is serialized and/or deserialized. header_length defines the amount of data present in the payload_buffer. Additionally I would skip adding the header_length itself as it is implicitly encoded by the length of the payload_buffer.

@@ -70,9 +71,16 @@ pub struct TcpHeader {
///the URG control bit set.
pub urgent_pointer: u16,
///Buffer containing the options of the header (note that the data_offset defines the actual length). Use the options() method if you want to get a slice that has the actual length of the options.
#[cfg_attr(feature = "serde", serde(skip), serde(default = "default_options_buffer"))]
Copy link
Owner

@JulianSchmid JulianSchmid Dec 17, 2022

Choose a reason for hiding this comment

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

I think a manual implementation of Serialize & Deserialize is needed for TcpHeader as well. Only the parts of the options_buffer that is actually filled should be serialized and/or deserialized. The length of actually filled data in the options_buffer is defined by the _data_offset field. The _data_offset field itself can be skipped when serializing as it is implicitly encoded in the length of the options_buffer.

We could also think about instead serializing the decoded options if that is possible. But that is maybe overkill.

Comment on lines 31 to 33
options_len: u8,
#[cfg_attr(feature = "serde", serde(skip), serde(default = "default_options_buffer"))]
options_buffer: [u8;40]
Copy link
Owner

@JulianSchmid JulianSchmid Dec 17, 2022

Choose a reason for hiding this comment

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

Same as with the TcpHeader & Ipv6RawExtension I would implement Serialize & Deserialize manually as options buffer is not required to be fully filled (same comments from the other two types also apply here).

@JulianSchmid
Copy link
Owner

Sorry I forgot: Thanks for the pull request 👍 .

@codecov
Copy link

codecov bot commented Dec 17, 2022

Codecov Report

Base: 99.63% // Head: 99.58% // Decreases project coverage by -0.05% ⚠️

Coverage data is based on head (cb9d36c) compared to base (05ac511).
Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #43      +/-   ##
==========================================
- Coverage   99.63%   99.58%   -0.06%     
==========================================
  Files          51       51              
  Lines       21898    21910      +12     
==========================================
  Hits        21818    21818              
- Misses         80       92      +12     
Impacted Files Coverage Δ
src/internet/ip.rs 100.00% <ø> (ø)
src/internet/ip_authentication.rs 98.52% <0.00%> (-1.48%) ⬇️
src/internet/ipv4.rs 99.40% <0.00%> (-0.60%) ⬇️
src/internet/ipv4_extensions.rs 100.00% <ø> (ø)
src/internet/ipv6.rs 100.00% <ø> (ø)
src/internet/ipv6_extensions.rs 100.00% <ø> (ø)
src/internet/ipv6_fragment.rs 100.00% <ø> (ø)
src/internet/ipv6_raw_extension.rs 97.87% <0.00%> (-2.13%) ⬇️
src/link/ethernet.rs 100.00% <ø> (ø)
src/link/vlan_tagging.rs 100.00% <ø> (ø)
... and 6 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@daviessm
Copy link
Author

Hi @JulianSchmid, thanks for the review! I implemented this because I thought I needed it in a project but ended up writing a custom serializer in my code instead so I won't have any time to work on this any more. I'd be happy for this to be closed or taken over by someone else, whatever works best for you.

@JulianSchmid
Copy link
Owner

Hi @daviessm , then I would take over the PR and implement it.

@JulianSchmid JulianSchmid changed the base branch from master to serde December 18, 2022 12:44
@JulianSchmid JulianSchmid marked this pull request as ready for review December 18, 2022 12:44
@JulianSchmid JulianSchmid merged commit ace6da1 into JulianSchmid:serde Dec 18, 2022
@JulianSchmid
Copy link
Owner

I moved to branch to this repo and opened up a new PR #45

@daviessm daviessm deleted the serde branch December 18, 2022 18:36
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