umqtt.simple: refactor packet de/encoding and fix remaining length encoding (fixes #284)#303
umqtt.simple: refactor packet de/encoding and fix remaining length encoding (fixes #284)#303SpotlightKid wants to merge 3 commits intomicropython:masterfrom
Conversation
4365d12 to
367bb92
Compare
…coding (fixes micropython#284) * Add `_varlen_encode` method to write variable length encoded remaining length bytes to packet buffer and use it consistently. * Use `int.from_bytes/to_bytes` to de/encode short integers and replace `ustruct` usage with it. * Correctly separate bytes of fixed and variable header in `connect` method. * Comment out unused import of `ubinascii.hexlify`.
…ent which can optionally be used with examples
367bb92 to
65a29fe
Compare
|
@pfalcon this looks like an important bugfix - any chance you could review this? |
|
@Kriechi It seems that only the fork (or original, depending on how you look at it) of I could re-submit my PR there, but I have basically given up on MicroPython, and I probably won't put any more effort into it. Feel free to take this PR (and any others I have made in this repo) and re-submit it (them) to pfalcon's repo. |
|
Thank you @SpotlightKid! Without your refactor bug fix I wasn't able to subscribe to my AWS topic, although it was only 63 bytes in length. Now it is working! |
|
Closing this since I'm cleaning my unmerged PRs and this hasn't been acted upon in years. |
As stated in #284, the
MQTTClient.subscribemethod doesn't handle topic lengths >= 122 correctly, since it only allocates one byte for the remaining length portion of the SUBSCRIPTION packet. I've refactored the variable length encoding of the remaining length bytes to use the new_varlen_encodemethod consistently and also got rid of the usage of theustructmodule._varlen_encodemethod to write variable length encoded remaining length bytes to packet buffer and use it consistently.int.from_bytes/to_bytesto de/encode short integers and replaceustructusage with it.connectmethod.In a separate commit I've also removed all (commented ou) debug printing calls in
simple.pyand added a debug wrapper forMQTTClient(umqtt_debug.py) to the examples, which can optionally be used with examples, and I've also expandedexample_pub.pyandexample_sub.pyso that they can be parametrized form the command line. If desired, I can separate this commit into an extra PR.This PR is based on the branch for PR #302. If the latter is merged, I will rebase this on master.