aboutsummaryrefslogtreecommitdiff
path: root/src/utils.lua
blob: 83e1d46ae3d6d427614797135f27fba9b143aefe (plain)
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
--
-- ~~~ helper utils
--

-- string -> hex
function string.tohex(str)
    return (str:gsub(".", function (c)
        return string.format("%02X", string.byte(c))
    end))
end

-- hex -> string
function string.fromhex(str)
    return (str:gsub("..", function (cc)
        return string.char(tonumber(cc, 16))
    end))
end

-- table[start, end] -> hex
function table.extracthex(response, start, last)

    local result = {}

    table.move(response, start, last, 1, result)
    result = string.tohex(table.concat(result))

    return result

end