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

Frame: decode payload length to return early [unverified] #24

Closed
wants to merge 1 commit into from

Conversation

678098
Copy link
Contributor

@678098 678098 commented Nov 5, 2023

A small optimization for partial Frames.
I have a feeling though that it makes things a bit more complicated, especially addressing buffer via exact offsets like buffer[3].
Might be good to add const size_t constants for these offsets.

return Frame::PARTIAL;
}

// Finally decode the skipped parts of the header.
bsl::memcpy(&frame->d_type, &buffer[0], sizeof(frame->d_type));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Side effect: partial Frame object will not be modified in any way during decode.

bdlb::BigEndianUint32 payloadLength;
bsl::memcpy(&payloadLength, &buffer[3], sizeof(payloadLength));

if ((frameOverhead() + payloadLength) > bufferLen) {
if (bufferLen < (frameOverhead() + payloadLength)) {
Copy link
Contributor Author

@678098 678098 Nov 5, 2023

Choose a reason for hiding this comment

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

Turned from left to right, similar to line 65

if (bufferLen < frameOverhead()) {

Copy link
Contributor

@willhoy willhoy left a comment

Choose a reason for hiding this comment

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

LGTM

@678098 678098 changed the title Frame: decode payload length to return early Frame: decode payload length to return early [unverified] Nov 30, 2023
@678098
Copy link
Contributor Author

678098 commented Nov 30, 2023

Closing this PR, the other PR contains the same changes with Verified status

@678098 678098 closed this Nov 30, 2023
@678098 678098 deleted the 231105_partial_frame_decode branch November 30, 2023 13:24
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