Skip to content


Subversion checkout URL

You can clone with
Download ZIP
MessagePack for LuaJIT (using FFI, no bindings)
Lua Makefile
Branch: master

add a standalone test that (sometimes) fails for PR #11

As often with LuaJIT, changing any single innocuous line
in this file will hide the problem, hence the useless function
definition and local declarations...

Run it like this:

    while true; do
        luajit tests/pr-11.lua || exit 1
latest commit 5ae0290c57
@catwell authored



This is yet another implementation of MessagePack for LuaJIT. However, unlike luajit-msgpack, luajit-msgpack-pure does not depend on the MessagePack C library. Everything is re-implemented in LuaJIT code (using the FFI but only to manipulate data structures).


If I had to pick a single MessagePack implementation, it would be lua-MessagePack. It is pure Lua, its performance is very close to luajit-msgpack-pure and it supports the latest revision of the standard. If it had existed earlier, I would not have written this one. If you start a new project, use it.

Another interesting implementation is lua-cmsgpack, written in C specifically for use in Redis.

Other implementations:

Before luajit-msgpack-pure, I had written luajit-msgpack, a FFI binding which is now deprecated.


  • Missing datatype tests
  • Comparison tests vs. other implementations



local mp = require "luajit-msgpack-pure"
local my_data = {this = {"is",4,"test"}}
local encoded = mp.pack(my_data)
local offset,decoded = mp.unpack(encoded)
assert(offset == #encoded)

Concatenating encoded data

local mp = require "luajit-msgpack-pure"
local my_data_1 = 42
local my_data_2 = "foo"
local encoded = mp.pack(my_data_1) .. mp.pack(my_data_2)
local offset_1,decoded_1 = mp.unpack(encoded)
assert(decoded_1 == 42)
local offset_2,decoded_2 = mp.unpack(encoded,offset_1)
assert(decoded_2 == "foo")
local offset_3,decoded_3 = mp.unpack(encoded,offset_2)
assert((not offset_3) and (decoded_3 == nil))

Setting floating point precision

local mp = require "luajit-msgpack-pure"
local my_data = math.pi
local encoded_1 = mp.pack(my_data) -- default is double
local offset_1,decoded_1 = mp.unpack(encoded_1)
assert(offset_1 == 9) -- 1 byte overhead + 8 bytes double
assert(decoded_1 == math.pi)
local encoded_2 = mp.pack(my_data)
local offset_2,decoded_2 = mp.unpack(encoded_2)
assert(offset_2 == 5) -- 1 byte overhead + 5 bytes float
assert(decoded_2 ~= math.pi) -- loss of precision
mp.set_fp_type("double") -- back to double precision
local encoded_3 = mp.pack(my_data)
local offset_3,decoded_3 = mp.unpack(encoded_3)
assert((offset_3 == 9) and (decoded_3 == math.pi))


Copyright (c) 2011-2014 Pierre Chapuis

Something went wrong with that request. Please try again.