https://github.com/xiaooloong/lua-resty-struct
convert between binary and lua, based on luajit. OpenResty 网络协议基础库
https://github.com/xiaooloong/lua-resty-struct
luajit luajit-ffi openresty
Last synced: 8 months ago
JSON representation
convert between binary and lua, based on luajit. OpenResty 网络协议基础库
- Host: GitHub
- URL: https://github.com/xiaooloong/lua-resty-struct
- Owner: xiaooloong
- License: bsd-2-clause
- Archived: true
- Created: 2017-09-12T05:29:14.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-18T15:06:54.000Z (over 8 years ago)
- Last Synced: 2024-08-03T13:06:08.972Z (over 1 year ago)
- Topics: luajit, luajit-ffi, openresty
- Language: Lua
- Homepage:
- Size: 9.77 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README-zh.md
- License: LICENSE
Awesome Lists containing this project
README
# Resty Struct
OpenResty 网络协议基础库,用于解析和构造二进制数据
用法和 python 的 [struct][1] 库相似
代码开发中,请勿用于项目
例:
```lua
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.python.org/2/library/struct.html