ProductPromotion
Logo

Lua

made by https://0x3d.site

GitHub - antirez/lua-cmsgpack: A self contained Lua MessagePack C implementation.
A self contained Lua MessagePack C implementation. - antirez/lua-cmsgpack
Visit Site

GitHub - antirez/lua-cmsgpack: A self contained Lua MessagePack C implementation.

GitHub - antirez/lua-cmsgpack: A self contained Lua MessagePack C implementation.

README for lua-cmsgpack.c

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.

INSTALLATION

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);

USAGE

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:

  • pack(arg1, arg2, ..., argn) - pack any number of lua objects into one msgpack stream. returns: msgpack
  • unpack(msgpack) - unpack all objects in msgpack to individual return values. returns: object1, object2, ..., objectN
  • unpack_one(msgpack); unpack_one(msgpack, offset) - unpacks the first object after offset. returns: offset, object
  • unpack_limit(msgpack, limit); unpack_limit(msgpack, limit, offset) - unpacks the first limit objects and returns: offset, object1, objet2, ..., objectN (up to limit, but may return fewer than limit if not that many objects remain to be unpacked)

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:

  • A table is converted into a MessagePack array type only if all the keys are composed of incrementing integers starting at 1 end ending at N, without holes, without additional non numerical keys. All the other tables are converted into maps.
  • An empty table is always converted into a MessagePack array, the rationale is that empty lists are much more common than empty maps (usually used to represent objects with fields).
  • A Lua number is converted into an integer type if floor(number) == number, otherwise it is converted into the MessagePack float or double value.
  • When a Lua number is converted to float or double, the former is preferred if there is no loss of precision compared to the double representation.
  • When a MessagePack big integer (64 bit) is converted to a Lua number it is possible that the resulting number will not represent the original number but just an approximation. This is unavoidable because the Lua numerical type is usually a double precision floating point type.

TESTING

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

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.

CREDITS

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.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory