umqtt.simple: Encode subscribe Remaining Length as VBI.#1142
umqtt.simple: Encode subscribe Remaining Length as VBI.#1142pablogventura wants to merge 4 commits 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>
|
Thanks for the fix. Can you try and reduce compiled .mpy code size here? Eg by creating a helper function, or even combining |
Factor Remaining Length VBI and ACK wait into _send_subunsub to reduce .mpy size after the long-topic fix. Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
|
Thanks. I combined the shared path into
Unix mock tests still pass. |
Factor the Variable Byte Integer encoder into a module helper and reuse it from connect, publish, and the subscribe/unsubscribe path to cut .mpy size. Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
|
Thanks again. Further size pass in the latest commit: shared
Unix mock tests still pass. |
Use ack_n to decide whether to include the QoS byte so ruff E711 passes without growing the compiled .mpy size. Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
|
Fixed the ruff E711 failure:
|
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. This PR encodes
Remaining Length that way for subscribe/unsubscribe, sharing a small
_encode_lenhelper withconnectandpublish.Testing
micropython micropython/umqtt.simple/test_umqtt_simple.py(mock socket, no broker):
82 80 01)a2 80 01)simple.mpyviampy-crossvsupstream/master: 2512 -> 2515 bytes (+3).Trade-offs and Alternatives
_send_subunsub; Remaining Length encodingis factored into
_encode_lenand reused by connect/publish to keep.mpysize close to master.
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.