GithubHelp home page GithubHelp logo

pombredanne / msgpuck Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rtsisyk/msgpuck

0.0 1.0 0.0 256 KB

A simple and efficient MsgPack binary serialization library in a self-contained header file

License: BSD 2-Clause "Simplified" License

msgpuck's Introduction

MsgPuck

MsgPuck is a simple and efficient MsgPack binary serialization library in a self-contained header file.

  • Can be easily incorporated into your project
  • Is very easy to use (see examples below)
  • Is fully tested and documented
  • Has clean and readable C source code
  • Is published under the very liberal license (BSD-2)

Status

MsgPuck is in beta stage. Latest MsgPack specification (2013-09) is supported.

The library is fully documented and covered by unit tests.

[Build Status] (https://travis-ci.org/rtsisyk/msgpuck)

Examples

Encoding:

char buf[1024];

char *w = buf;
w = mp_encode_array(w, 4)
w = mp_encode_uint(w, 10);
w = mp_encode_str(w, "hello world", strlen("hello world"));
w = mp_encode_bool(w, true);
w = mp_encode_double(w, 3.1415);

Validating:

const char *b = buf;
bool is_valid = mp_check(&b);
assert(is_valid);
assert(b == w);

Decoding:

uint32_t size;
uint64_t ival;
const char *sval;
uint32_t sval_len;
bool bval;
double dval;

const char *r = buf;
size = mp_decode_array(&r);
/* size is 4 */

ival = mp_decode_uint(&r);
/* ival is 10; */

sval = mp_decode_str(&r, &sval_len);
/* sval is "hello world", sval_len is strlen("hello world") */

bval = mp_decode_bool(&r);
/* bval is true */

dval = mp_decode_double(&r);
/* dval is 3.1415 */

assert(r == w);

Installation

You need a C99 or C++03 compatible compiler to use the header.

Just use the header

Add this project as a git submodule or just copy msgpuck.h to your project. Include msgpuck.h as usual and define MP_SOURCE 1 exactly in a single compilation unit (*.c or *.cc file):

#define MP_SOURCE 1 /* define in a single .c/.cc file */
#include "msgpuck.h"

All non-inline versions of functions and global lookup tables will be stored in the file. MP_SOURCE must be defined exactly in a single compilation unit in you application, otherwise linker errors occur.

Compile as a shared library

You can also compile and install MsgPuck as a system-wide shared library:

cmake .
make
make test
make install

Include msgpuck.h and link your application with -lmsgpuck.

Documentation

API documentation can be also generated using make doc (Doxygen is required).

Contacts

MsgPuck was written to use within Tarantool - the world's first full-featured MsgPack-based database.

msgpuck's People

Contributors

rtsisyk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.