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

primitive wrapper types for u16 & u32 #97

Merged
merged 3 commits into from
May 11, 2020
Merged

primitive wrapper types for u16 & u32 #97

merged 3 commits into from
May 11, 2020

Conversation

zeeshanlakhani
Copy link
Member

@zeeshanlakhani zeeshanlakhani commented May 9, 2020

Description

"new" types to ensure proper conversion of packet data to/from network byte order.

Includes:

  • impls bit and/or/xor/*assign and not (!) for types
  • includes updates throughout the packets module to use these types
  • added flag tests

Notes:

Checklist

  • Associated tests
  • Associated documentation

@codecov
Copy link

codecov bot commented May 9, 2020

Codecov Report

Merging #97 into master will increase coverage by 0.28%.
The diff coverage is 86.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #97      +/-   ##
==========================================
+ Coverage   67.07%   67.36%   +0.28%     
==========================================
  Files          62       63       +1     
  Lines        5260     5331      +71     
==========================================
+ Hits         3528     3591      +63     
- Misses       1732     1740       +8     
Impacted Files Coverage Δ
core/src/net/cidr/v4.rs 66.66% <ø> (ø)
core/src/net/cidr/v6.rs 66.66% <ø> (ø)
core/src/packets/checksum.rs 92.30% <ø> (ø)
core/src/packets/icmp/v6/ndp/router_solicit.rs 54.76% <ø> (ø)
core/src/packets/icmp/v6/time_exceeded.rs 68.65% <ø> (ø)
core/src/packets/ip/mod.rs 47.36% <ø> (ø)
core/src/packets/mod.rs 96.05% <ø> (ø)
core/src/runtime/mod.rs 0.00% <ø> (ø)
core/src/testils/criterion.rs 0.00% <ø> (ø)
core/src/packets/ethernet.rs 80.13% <33.33%> (-1.08%) ⬇️
... and 24 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b0ab55...c5f655c. Read the comment docs.

@zeeshanlakhani zeeshanlakhani changed the title Zl/be types be wrapper types May 9, 2020
@zeeshanlakhani zeeshanlakhani changed the title be wrapper types big-endian wrapper types and conversions May 9, 2020
Copy link
Contributor

@drunkirishcoder drunkirishcoder left a comment

Choose a reason for hiding this comment

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

really love the compiler safety this change introduces.

one more comment, fix the commit message. it's too long. see our contributing guideline. lol

core/src/packets/mod.rs Outdated Show resolved Hide resolved
core/src/packets/types.rs Outdated Show resolved Hide resolved
use std::fmt;
use std::ops;

/// Big-endian wrapper type for `u16`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The 16-bit unsigned integer in big-endian order.

core/src/packets/types.rs Outdated Show resolved Hide resolved

impl u16be {
/// U16 Big-Endian 0
pub const BE0: u16be = u16be(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

actually we can call this MIN, and we can copy the doc over as well. why not.

The smallest value that can be represented by this integer type.

core/src/packets/ethernet.rs Show resolved Hide resolved
core/src/packets/icmp/v6/ndp/redirect.rs Show resolved Hide resolved
core/src/packets/icmp/v6/too_big.rs Show resolved Hide resolved
core/src/packets/ip/v4.rs Show resolved Hide resolved
core/src/packets/ip/v6/fragment.rs Show resolved Hide resolved
@zeeshanlakhani zeeshanlakhani changed the title big-endian wrapper types and conversions primitive wrapper types for u16 & u32 May 9, 2020
Zeeshan Lakhani added 2 commits May 11, 2020 12:06
…packet data to/from network byte order

- impls bit and/or/xor/*assign and not (!) for types
- includes updates throughout the packets module to use these types
- added flag tests
Copy link
Contributor

@drunkirishcoder drunkirishcoder left a comment

Choose a reason for hiding this comment

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

A few small comments. once addressed. 👍

pub struct u16be(pub u16);

impl u16be {
/// The 16-bit unsigned integer in big-endian order.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you made this change in the wrong place. this is for the main type description above. description here should be,

The smallest value that can be represented by this integer type.

Copy link
Member Author

Choose a reason for hiding this comment

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

derp.

@@ -34,10 +34,10 @@ use std::time::{Duration, Instant};
pub trait BencherExt {
/// Times a `routine` with an input generated via a `proptest strategy`
/// batch of input, and then times the iteration of the benchmark over the
/// input. See [`BatchSize`] for details on choosing the batch size. The
/// input. See [BatchSize] for details on choosing the batch size. The
Copy link
Contributor

Choose a reason for hiding this comment

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

this is actually a rust type.

Copy link
Member Author

Choose a reason for hiding this comment

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

diff lib, but ok, yeah.

@@ -16,12 +16,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

//! Defines extended [`proptest`] [`Arbitrary`] traits and [`Strategies`] for
//! Defines extended [proptest] [Arbitrary] traits and [Strategies] for
Copy link
Contributor

Choose a reason for hiding this comment

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

Arbitrary and Strategy are both traits. Maybe change Strategies to singular? Something like

Defines extended proptest Arbitrary and Strategy traits...

@zeeshanlakhani zeeshanlakhani merged commit 3e085e8 into master May 11, 2020
@zeeshanlakhani zeeshanlakhani deleted the zl/be-types branch May 11, 2020 18:04
zeeshanlakhani added a commit that referenced this pull request May 11, 2020
primitive wrapper types for u16 & u32 to ensure proper conversion of packet data to/from network byte order.

Includes:

- impls bit and/or/xor/*assign and not (!) for types
- includes updates throughout the packets module to use these types
- additional flag tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants