forked from luca/mineqtt
1
0
Fork 0

feat: varint encoding

This commit is contained in:
Luca 2024-09-05 21:31:52 +02:00
parent 8d283790b6
commit 2311ac23ae
1 changed files with 14 additions and 0 deletions

View File

@ -42,6 +42,20 @@ local readVarint = function (conn, first_byte)
return n + (b << s), nil
end
local encodeVarint = function (n)
if n > 268435455 then
return nil, "number too large"
end
local data = ""
while n > 127 do
data = data .. string.char(0x80 | n & 0x7F)
n = n >> 7
end
return data .. string.char(n), nil
end
local MqttClient = {}
function mqtt.open (address, port)