-
-
Notifications
You must be signed in to change notification settings - Fork 317
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
refactor: update snappy frame decompress #7333
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #7333 +/- ##
============================================
+ Coverage 48.75% 48.76% +0.01%
============================================
Files 601 601
Lines 40222 40243 +21
Branches 2061 2067 +6
============================================
+ Hits 19609 19626 +17
- Misses 20575 20579 +4
Partials 38 38 |
Performance Report✔️ no performance regression detected Full benchmark results
|
case ChunkType.COMPRESSED: | ||
case ChunkType.UNCOMPRESSED: { | ||
const checksum = frame.subarray(0, 4); | ||
const data = frame.subarray(4); | ||
|
||
if (type === ChunkType.COMPRESSED) { | ||
result.append(uncompress(data.subarray(4))); | ||
} | ||
if (type === ChunkType.UNCOMPRESSED) { | ||
result.append(data.subarray(4)); | ||
const uncompressed = type === ChunkType.COMPRESSED ? uncompress(data, UNCOMPRESSED_CHUNK_SIZE) : data; | ||
if (uncompressed.length > UNCOMPRESSED_CHUNK_SIZE) { | ||
throw "malformed input: too large"; | ||
} | ||
if (crc(uncompressed).compare(checksum) !== 0) { | ||
throw "malformed input: bad checksum"; | ||
} | ||
result.append(uncompressed); | ||
} |
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.
I would prefer to not mix ChunkType.COMPRESSED
and ChunkType.UNCOMPRESSED
logic in one case.
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.
LGTM
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.
LGTM 🎸 Just a question on why you passed hex instead of decimal format
chunks.append(Uint8Array.from([ChunkType.UNCOMPRESSED, 0x80, 0x00, 0x00])); | ||
// first 4 bytes are checksum | ||
// 0xffffffff is clearly an invalid checksum | ||
chunks.append(Uint8Array.from(Array.from({length: 0x80}, () => 0xff))); |
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.
why not use 128 here? Guessing this is a snappy spec thing but curious none-the-less
chunks.append(Uint8Array.from(Array.from({length: 0x80}, () => 0xff))); | |
chunks.append(Uint8Array.from(Array.from({length: 128}, () => 0xff))); |
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.
just an artifact from a test case I had been provided, there's nothing special about 128.
🎉 This PR is included in v1.25.0 🎉 |
Motivation
Description