umqtt.simple: Encode subscribe Remaining Length as VBI. - #1142
Conversation
|
Thanks for the fix. Can you try and reduce compiled .mpy code size here? Eg by creating a helper function, or even combining |
|
Thanks. I combined the shared path into
Unix mock tests still pass. |
|
Thanks again. Further size pass in the latest commit: shared
Unix mock tests still pass. |
|
Fixed the ruff E711 failure:
|
|
See #303 for a previous attempt at this. Is there anything from that PR that's missed in this PR here? |
|
Thanks for the pointer to #303. I compared it against this PR. For the Remaining Length bug itself (#284 / #969), nothing essential from #303 is missing here: #303 was a broader refactor on top of the bug fix: shared On size, compiling
So the focused approach here is substantially smaller than porting the #303 refactor onto the current tree. Happy to open a follow-up later for any of the non-bug items from #303 if you want them (e.g. username without password). |
|
Thanks for investigating #303 in detail. I agree the approach here looks better: smaller and covers the new I noticed the new test is not running under CI. Please enable it using the following: --- a/tools/ci.sh
+++ b/tools/ci.sh
@@ -57,6 +57,7 @@ function ci_package_tests_run {
export MICROPYPATH
for test in \
micropython/drivers/storage/sdcard/sdtest.py \
+ micropython/umqtt.simple/test_umqtt_simple.py \
micropython/xmltok/test_xmltok.py \
python-ecosys/requests/test_requests.py \
python-stdlib/argparse/test_argparse.py \After that's done, this PR should be good to merge. |
|
Thanks. Added Verified locally with the same invocation CI uses: |
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>
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>
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>
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>
Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
eecbe36 to
6a9f163
Compare
|
Merged! Thanks for your work on this, it's a good improvement. And nice that the code size impact was almost zero. |
|
Thanks for merging, and for the careful review throughout. I'm glad to contribute to micropython and happy to keep helping. If there is any area or issue you would particularly like me to focus on next, just point me at it. |
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.