Skip to content
This repository

MessagePack implementation for C and C++ / msgpack.org[C/C++]

Merge pull request #81 from watsonsong/master

fix compile error on Linux by gcc 4.7
latest commit 9f33266f23
Nobuyuki Kubota nobu-k authored
Octocat-spinner-32 example Replaced deprecated functions in example/stream.cc February 07, 2014
Octocat-spinner-32 src fix compile error on Linux by gcc 4.7 April 01, 2014
Octocat-spinner-32 test Fixed failing test zone_allocate_constructor. March 18, 2014
Octocat-spinner-32 .gitignore Imported .gitignore from the original MessagePack git repository January 03, 2013
Octocat-spinner-32 AUTHORS reorganized tree January 03, 2013
Octocat-spinner-32 COPYING reorganized tree January 03, 2013
Octocat-spinner-32 ChangeLog version 0.5.8 December 22, 2013
Octocat-spinner-32 Doxyfile reorganized tree January 03, 2013
Octocat-spinner-32 LICENSE reorganized tree January 03, 2013
Octocat-spinner-32 Makefile.am reorganized tree January 03, 2013
Octocat-spinner-32 NOTICE reorganized tree January 03, 2013
Octocat-spinner-32 QUICKSTART-C.md Imported quickstarts from wiki August 17, 2013
Octocat-spinner-32 QUICKSTART-CPP.md Fix typo in QUICKSTART-CPP March 24, 2014
Octocat-spinner-32 README.md Fixed some URL syntaxes December 22, 2013
Octocat-spinner-32 README_crosslang.md reorganized tree January 03, 2013
Octocat-spinner-32 bootstrap reorganized tree January 03, 2013
Octocat-spinner-32 cases.json reorganized tree January 03, 2013
Octocat-spinner-32 cases.mpac reorganized tree January 03, 2013
Octocat-spinner-32 cases_compact.mpac reorganized tree January 03, 2013
Octocat-spinner-32 cases_gen.rb reorganized tree January 03, 2013
Octocat-spinner-32 configure.in version 0.5.8 December 22, 2013
Octocat-spinner-32 crosslang.cc reorganized tree January 03, 2013
Octocat-spinner-32 crosslang.rb reorganized tree January 03, 2013
Octocat-spinner-32 msgpack.pc.in reorganized tree January 03, 2013
Octocat-spinner-32 msgpack_vc.postbuild.bat reorganized tree January 03, 2013
Octocat-spinner-32 msgpack_vc8.sln reorganized tree January 03, 2013
Octocat-spinner-32 msgpack_vc8.vcproj reorganized tree January 03, 2013
Octocat-spinner-32 pack_define.h reorganized tree January 03, 2013
Octocat-spinner-32 pack_template.h Merge pull request #46 from redboltz/fixed_size_type December 22, 2013
Octocat-spinner-32 preprocess reorganized tree January 03, 2013
Octocat-spinner-32 sysdep.h reorganized tree January 03, 2013
Octocat-spinner-32 unpack_define.h str 8 and bin 8/16/32 support in deserializer August 17, 2013
Octocat-spinner-32 unpack_template.h fixed a typo in a comment August 21, 2013
README.md

Msgpack for C/C++

It's like JSON but small and fast.

Overview

MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.

License

Msgpack is Copyright (C) 2008-2010 FURUHASHI Sadayuki and licensed under the Apache License, Version 2.0 (the "License"). For details see the COPYING file in this directory.

Contributing

The source for msgpack-c is held at msgpack-c github.com site.

To report an issue, use the msgpack-c issue tracker at github.com.

Using Msgpack

Building and Installing

Install from git repository

You will need gcc (4.1.0 or higher), autotools.

$ git clone https://github.com/msgpack/msgpack-c.git
$ cd msgpack-c
$ ./bootstrap
$ ./configure
$ make
$ sudo make install

Install from package

UNIX-like platform with ./configure

On typical UNIX-like platforms, download source package from Releases and run ./configure && make && make install. Example:

$ wget https://github.com/msgpack/msgpack-c/releases/download/cpp-0.5.8/msgpack-0.5.8.tar.gz
$ tar zxvf msgpack-0.5.8.tar.gz
$ cd msgpack-0.5.8
$ ./configure
$ make
$ sudo make install
FreeBSD with Ports Collection

On FreeBSD, you can use Ports Collection. Install net/msgpack package.

Gentoo Linux with Portage

On Gentoo Linux, you can use emerge. Install dev-libs/msgpack package.

Mac OS X with MacPorts

On Mac OS X, you can install MessagePack for C using MacPorts.

$ sudo port install msgpack

You might need to run sudo port selfupdate before installing to update the package repository.

You can also install via Homebrew.

$ sudo brew install msgpack
Windows

On Windows, download source package from here and extract it. Open msgpack_vc8.vcproj or msgpack_vc2008 file and build it using batch build. It builds libraries in lib/ folder and header files in include/ folder.

You can build using command line as follows:

> vcbuild msgpack_vc2008.vcproj
> dir lib       % DLL files are here
> dir include   % header files are here

Linking with an Application

Include msgpack.hpp (or msgpack.h for C) in your application and link with libmsgpack. Here is a typical gcc link command:

gcc -lmsgpack myapp.c -o myapp

Code Example

#include <msgpack.hpp>
#include <vector>

int main(void) {
    // This is target object.
    std::vector<std::string> target;
    target.push_back("Hello,");
    target.push_back("World!");

    // Serialize it.
    msgpack::sbuffer sbuf;  // simple buffer
    msgpack::pack(&sbuf, target);

    // Deserialize the serialized data.
    msgpack::unpacked msg;    // includes memory pool and deserialized object
    msgpack::unpack(&msg, sbuf.data(), sbuf.size());
    msgpack::object obj = msg.get();

    // Print the deserialized object to stdout.
    std::cout << obj << std::endl;    // ["Hello," "World!"]

    // Convert the deserialized object to staticaly typed object.
    std::vector<std::string> result;
    obj.convert(&result);

    // If the type is mismatched, it throws msgpack::type_error.
    obj.as<int>();  // type is mismatched, msgpack::type_error is thrown
}

Quickstart Guides

For more detailed examples see QuickStart for C and QuickStart for C++.

Something went wrong with that request. Please try again.