lua-resty-struct

基于 luajit,实现二进制数据与 Lua 之间的转换。用于网络协议。

$ opm get xiaooloong/lua-resty-struct

Resty Struct

中文说明

基于 luajit,实现二进制数据与 Lua 之间的转换。

使用方式类似 Python 的 [struct][1] 类。

此模块仍在开发中,请勿使用。

示例

    local struct = require 'resty.struct'
    
    local binary, err = struct.pack('HHL', 1, 2, 3)
    
    if not binary then print(err) end
    
    local table, count = struct.unpack('HHL', binary)
    
    if table then
        for i = 1, count do
            print(table[i])
        end
    else
        print(count) -- error message instead
    end
    

[1]: https://docs.pythonlang.cn/2/library/struct.html

作者

xiaooloong

许可证

2bsd

依赖

luajit

版本