The Variable Byte Integer is encoded using an encoding scheme which uses a single byte for values up to 127. Larger values are handled as follows. The least significant seven bits of each byte encode the data, and the most significant bit is used to indicate whether there are bytes following in the representation. Thus, each byte encodes 128 values and a "continuation bit". The maximum number of bytes in the Variable Byte Integer field is four. The encoded value MUST use the minimum number of bytes necessary to represent the value [MQTT-1.5.5-1]. This is shown in Table 1‑1 Size of Variable Byte Integer.
So, if Variable Byte Integer is greater than 127, the length will occupy 2 bytes instead of 1.
Hence , here pos always increase 1 is not correct.
According to MQTT 5 protocol https://docs.oasis-open.org/mqtt/mqtt/v5.0/mqtt-v5.0.html, chapter, 1.5.5 Variable Byte Integer
So, if
Variable Byte Integer
is greater than 127, the length will occupy 2 bytes instead of 1.Hence , here
pos
always increase 1 is not correct.