-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpack.lua
More file actions
58 lines (41 loc) · 1.14 KB
/
pack.lua
File metadata and controls
58 lines (41 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--
-- SPDX-FileCopyrightText: (c) 2024 Ring Zero Desenvolvimento de Software LTDA
-- SPDX-License-Identifier: GPL-2.0-only
--
local linux = require("linux")
local ntoh16, ntoh32 = linux.ntoh16, linux.ntoh32
local hton16, hton32 = linux.hton16, linux.hton32
local pack = {}
function pack.unpacker(packet, base)
base = base or 0
local u8 = function (offset)
return packet:getuint8(base + offset)
end
local be16 = function (offset)
return ntoh16(packet:getuint16(base + offset))
end
local be32 = function (offset)
return ntoh32(packet:getuint32(base + offset))
end
local str = function (offset, length)
return packet:getstring(base + offset, length)
end
return str, u8, be16, be32
end
function pack.packer(packet, base)
base = base or 0
local u8 = function (offset, value)
packet:setuint8(base + offset, value)
end
local be16 = function (offset, value)
packet:setuint16(base + offset, hton16(value))
end
local be32 = function (offset, value)
packet:setuint32(base + offset, hton32(value))
end
local str = function (offset, value)
packet:setstring(base + offset, value)
end
return str, u8, be16, be32
end
return pack