-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: refactor and fix bug for snappy frame lib #3
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
Conversation
Signed-off-by: Chen Kai <281165273grape@gmail.com>
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.
Pull Request Overview
This PR refactors the Snappy framing implementation to fix critical bugs that prevent proper interoperability with external Snappy frame implementations. The changes address broken chunk-length calculations, incorrect CRC handling, and missing stream identifier validation.
- Fixes chunk length calculation that was using incorrect bit shifts, causing chunks >511 bytes to decode incorrectly
- Implements proper masked CRC-32C validation per Snappy frame specification
- Adds stream identifier validation and proper frame format enforcement
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Signed-off-by: Chen Kai <281165273grape@gmail.com>
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.
Pull Request Overview
Copilot reviewed 1 out of 3 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const compressed = try snappyz.encode(self.allocator, chunk_input); | ||
| defer self.allocator.free(compressed); | ||
|
|
||
| const compress_threshold = chunk_input.len - (chunk_input.len / 8); |
Copilot
AI
Oct 11, 2025
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.
The magic number 8 used for compression threshold calculation should be extracted as a named constant (e.g., compression_ratio_threshold = 8) to clarify its purpose and make it configurable.
| for (large_data, 0..) |*byte, idx| { | ||
| byte.* = @intCast((idx * 31) % 251); |
Copilot
AI
Oct 11, 2025
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.
The magic numbers 31 and 251 used for test data generation should be extracted as named constants to clarify their purpose as pseudo-random data generation parameters.
| for (large_data, 0..) |*byte, idx| { | |
| byte.* = @intCast((idx * 31) % 251); | |
| const test_data_multiplier = 31; | |
| const test_data_modulus = 251; | |
| for (large_data, 0..) |*byte, idx| { | |
| byte.* = @intCast((idx * test_data_multiplier) % test_data_modulus); |
Fix the snappy frame issues found by interop.