Skip to content

umqtt.simple: Encode subscribe Remaining Length as VBI.#1142

Open
pablogventura wants to merge 1 commit into
micropython:masterfrom
pablogventura:umqtt-subscribe-remaining-length
Open

umqtt.simple: Encode subscribe Remaining Length as VBI.#1142
pablogventura wants to merge 1 commit into
micropython:masterfrom
pablogventura:umqtt-subscribe-remaining-length

Conversation

@pablogventura

Copy link
Copy Markdown
Contributor

Summary

Fixes #969. subscribe (and unsubscribe) packed Remaining Length with
struct.pack_into(\"!BH\", ...), so values above 127 overflow a single byte
and long topics fail on the wire.

MQTT 3.1.1 section 2.2.3 requires a Variable Byte Integer. publish already
encodes Remaining Length that way; this PR uses the same pattern for
subscribe and unsubscribe without extracting a shared helper or changing
connect / publish.

Testing

  • Unix port: micropython micropython/umqtt.simple/test_umqtt_simple.py
    (mock socket, no broker):
    • short topic (single-byte Remaining Length)
    • subscribe with topic length 123 (Remaining Length 128 -> 82 80 01)
    • unsubscribe with topic length 124 (Remaining Length 128 -> a2 80 01)
  • simple.mpy via mpy-cross vs upstream/master: 2524 -> 2689 bytes (+165).

Trade-offs and Alternatives

  • The VBI loop is duplicated from publish rather than factored out, to keep
    the diff small and avoid touching working paths.
  • unsubscribe is included because it had the same one-byte Remaining Length
    bug.

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.

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>
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.

MQTT subscribe Remaining Length encoding is incorrect

1 participant