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

chore: drop byteorder dependency #30

Merged
merged 1 commit into from
Apr 8, 2024
Merged

chore: drop byteorder dependency #30

merged 1 commit into from
Apr 8, 2024

Conversation

paolobarbolini
Copy link
Contributor

@paolobarbolini paolobarbolini commented Apr 8, 2024

Feature or Problem

Drop the byteorder dependency, which could easily be replaced with functions from std and easier to read logic.

Related Issues

None

Release Information

next

Consumer Impact

One less dependency, and less unsafe code in the build

Testing

Read below

Unit Test(s)

None

Acceptance or Integration

None

Manual Verification

While manually verifying that the code is correct I've gotten even more confused at how this code works. Looking at the Go library the CRC is put at the end and read from the end, while here the CRC is written to the end and read from the start 🤷‍♂️. Are the tests wrong???

I've tried doing this and this seems to confirm my assumption:

diff --git a/src/crc.rs b/src/crc.rs
index 228880d..5dc5981 100644
--- a/src/crc.rs
+++ b/src/crc.rs
@@ -58,3 +58,23 @@ pub(crate) fn extract_crc(data: &mut Vec<u8>) -> Result<u16> {
     data.truncate(data.len() - 2);
     Ok(crc)
 }
+
+#[cfg(test)]
+mod tests {
+    use crate::crc::crc16;
+
+    use super::{extract_crc, push_crc};
+
+    #[test]
+    fn im_confused() {
+        let raw_data = rand::random::<[u8; 32]>();
+        let crc = crc16(&raw_data);
+
+        let mut data = raw_data.to_vec();
+        push_crc(&mut data);
+
+        let crc2 = extract_crc(&mut data).unwrap();
+        assert_eq!(raw_data, data.as_slice());
+        assert_eq!(crc, crc2);
+    }
+}

@brooksmtownsend
Copy link
Member

Thank you for filing this @paolobarbolini ! I'll take a look at this shortly to verify the behavior... seems weird.

Copy link
Member

@brooksmtownsend brooksmtownsend left a comment

Choose a reason for hiding this comment

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

This functionality looks like a great replacement! I had one request to try and avoid an unwrap()

src/crc.rs Outdated Show resolved Hide resolved
Signed-off-by: Paolo Barbolini <paolo.barbolini@m4ss.net>
Copy link
Member

@brooksmtownsend brooksmtownsend left a comment

Choose a reason for hiding this comment

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

I think your explanation is good enough that I can get over having an unwrap there 😉

@brooksmtownsend brooksmtownsend merged commit 333844d into wasmCloud:master Apr 8, 2024
4 checks passed
@brooksmtownsend
Copy link
Member

@paolobarbolini do you a need for this to be released? It's small enough I think it could be a patch.

@paolobarbolini
Copy link
Contributor Author

paolobarbolini commented Apr 8, 2024

Thanks for the merge. I'll see if I can send the second PR with the CRC moved to the end tomorrow.

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