module MQTT::VariableByteInteger

Overview

MQTT encodes lengths as a variable byte integer: seven bits of payload per byte, with the top bit signalling that another byte follows. Four bytes is the maximum, giving MQTT::MAX_REMAINING_LENGTH.

3.1.1 only uses this for the remaining length in the fixed header. 5.0 also uses it for the property section length and for subscription identifiers.

Defined in:

mqtt/variable_byte_integer.cr

Class Method Summary

Class Method Detail

def self.byte_size(value : UInt32) : Int32 #

Number of bytes the encoded form of value occupies


[View source]
def self.decode(byte1 : UInt8, byte2 : UInt8, byte3 : UInt8, byte4 : UInt8) : UInt32 #

NOTE : the caller passes every byte, including ones that were never read from the wire. Those default to zero and contribute nothing


[View source]
def self.encode(value : UInt32) : StaticArray(UInt8, 4) #

Always returns four bytes, the unused trailing ones are zero. .byte_size says how many of them belong on the wire


[View source]