umqtt.simple: refactor packet de/encoding and fix remaining length encoding (fixes #284) #303
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.
As stated in #284, the
MQTTClient.subscribe
method 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_encode
method consistently and also got rid of the usage of theustruct
module._varlen_encode
method to write variable length encoded remaining length bytes to packet buffer and use it consistently.int.from_bytes/to_bytes
to de/encode short integers and replaceustruct
usage with it.connect
method.In a separate commit I've also removed all (commented ou) debug printing calls in
simple.py
and added a debug wrapper forMQTTClient
(umqtt_debug.py
) to the examples, which can optionally be used with examples, and I've also expandedexample_pub.py
andexample_sub.py
so 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.