| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Lua-cmsgpack is a MessagePack implementation and bindings for Lua 5.1/5.2/5.3 in a self contained C file without external dependencies.
This library is open source software licensed under the BSD two-clause license.
Using LuaRocks (http://luarocks.org):
Install current stable release:
sudo luarocks install lua-cmsgpack
Install current Git master head from GitHub:
sudo luarocks install lua-cmsgpack --from=rocks-cvs
Install from current working copy
cd lua-cmsgpack/ sudo luarocks make rockspec/lua-cmsgpack-scm-1.rockspec
If you embed Lua and all modules into your C project, just add the lua_cmsgpack.c file and call the following function after creating the Lua interpreter:
luaopen_cmsgpack(L);
The exported API is very simple, consisting of four functions:
Basic API:
msgpack = cmsgpack.pack(lua_object1, lua_object2, ..., lua_objectN) lua_object1, lua_object2, ..., lua_objectN = cmsgpack.unpack(msgpack)
Detailed API giving you more control over unpacking multiple values:
resume_offset, lua_object1 = cmsgpack.unpack_one(msgpack) resume_offset1, lua_object2 = cmsgpack.unpack_one(msgpack, resume_offset) ... -1, lua_objectN = cmsgpack.unpack_one(msgpack, resume_offset_previous) resume_offset, lua_object1, lua_object2 = cmsgpack.unpack_limit(msgpack, 2) resume_offset2, lua_object3 = cmsgpack.unpack_limit(msgpack, 1, resume_offset1)
Functions:
When you reach the end of your input stream with unpack_one or unpack_limit, an offset of -1 is returned.
You may require "msgpack" or you may require "msgpack.safe". The safe version returns errors as (nil, errstring).
However because of the nature of Lua numerical and table type a few behavior of the library must be well understood to avoid problems:
Build and test:
mkdir build; cd build cmake .. make lua ../test.lua
You can build a 32-bit module on a 64-bit platform with:
mkdir build; cd build cmake -DBuild32Bit=ON .. make lua ../test.lua
Nested tables are handled correctly up to LUACMSGPACK_MAX_NESTING levels of nesting (that is set to 16 by default). Every table that is nested at a greater level than the maxium is encoded as MessagePack nil value.
It is worth to note that in Lua it is possible to create tables that mutually refer to each other, creating a cycle. For example:
a = {x=nil,y=5}
b = {x=a}
a['x'] = b
This condition will simply make the encoder reach the max level of nesting, thus avoiding an infinite loop.
This library was written by Salvatore Sanfilippo for Redis, but is maintained as a separated project by the author.
Some of the test vectors in "test.lua" are obtained from the Javascript MessagePack-JS library.
| Back | FazBrowse Home | New Git URL |