umqtt.simple: Encode subscribe Remaining Length as VBI.#1142
Open
pablogventura wants to merge 1 commit into
Open
umqtt.simple: Encode subscribe Remaining Length as VBI.#1142pablogventura wants to merge 1 commit into
pablogventura wants to merge 1 commit into
Conversation
Use the same variable-byte Remaining Length encoding as publish for subscribe and unsubscribe so long topics no longer overflow a single length byte. Fixes micropython#969. Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #969.
subscribe(andunsubscribe) packed Remaining Length withstruct.pack_into(\"!BH\", ...), so values above 127 overflow a single byteand long topics fail on the wire.
MQTT 3.1.1 section 2.2.3 requires a Variable Byte Integer.
publishalreadyencodes Remaining Length that way; this PR uses the same pattern for
subscribe and unsubscribe without extracting a shared helper or changing
connect/publish.Testing
micropython micropython/umqtt.simple/test_umqtt_simple.py(mock socket, no broker):
82 80 01)a2 80 01)simple.mpyviampy-crossvsupstream/master: 2524 -> 2689 bytes (+165).Trade-offs and Alternatives
publishrather than factored out, to keepthe diff small and avoid touching working paths.
unsubscribeis included because it had the same one-byte Remaining Lengthbug.
Generative AI
I used generative AI tools when creating this PR, but a human has checked the
code and is responsible for the code and the description above.