pack/unpack binary data in nginx+lua

37 views
Skip to first unread message

Андрей Еньшин

unread,
Jun 1, 2017, 11:54:20 AM6/1/17
to openresty-en
Hi2all!

I have to unpack binary data using unpack as i do it in Perl. There is lpack but i have no idea how i can bring it to openresty?
Or are there any other ability to unpack it using functionality from the box?

Thnaks

Jim Robinson

unread,
Jun 1, 2017, 4:25:09 PM6/1/17
to openresty-en
I've used https://github.com/antirez/lua-cmsgpack and thought it worked well.  Once they are installed under the openresty luajit/lib directory, you can just load them up and use them:

local cmsgpack = require("cmsgpack.safe")

local cpack = cmsgpack.pack

local cunpack = cmsgpack.unpack

...

local head, err = cpack(meta, status, response.header)

...

local meta, status, header, err = cunpack(head)


I happened to use a LuaRocks based installations for mine, though I see now that there is encouragement to use an OpenResty specific package manager (https://opm.openresty.org/): https://openresty.org/en/using-luarocks.html
Reply all
Reply to author
Forward
0 new messages