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

Add peek/peek_finalize to VariablePacket #24

Merged
merged 2 commits into from
Sep 25, 2018
Merged

Conversation

dpmkl
Copy link
Contributor

@dpmkl dpmkl commented Sep 24, 2018

VariablePacket::peek was refactored from parse to read the protocol header and additionally return the header bytes ( ignored in parse but used in peek_finalize ).
VariablePacket::peek_finialize reads the rest of the packet returning a decoded packet and the entire buffer.
VariablePacket::parse uses peek to read the header, no braking changes for anything existing.

The use case for this is that as a broker/bridge you want to be able to early reject connections by peeking into the fixed header if the control type is relevant to the current situation, logging/aborting/exiting without processing the remaining data. To avoid unnecessary encoding/decoding or rereading the buffer in order to forward the packet, the entire packet buffer is returned in peek_finalize.

Added basic tests for VariablePacket::parse and VariablePacket::peek(_finalize)

This affects only tokio async use.

@zonyitoo zonyitoo merged commit ad0b766 into zonyitoo:master Sep 25, 2018
@zonyitoo
Copy link
Owner

LGTM. Will be released in v0.6.0

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