Git Product home page Git Product logo

msgpack-c's Introduction

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++.

msgpack-c's People

Contributors

frsyuki avatar gfx avatar tokuhirom avatar muga avatar methane avatar tanakh avatar redboltz avatar nobu-k avatar makamaka avatar kazuki avatar kzk avatar moriyoshi avatar advect avatar dgryski avatar xerial avatar repeatedly avatar dbussink avatar nicolasdespres avatar hayamiz avatar firewood avatar mzp avatar watabiki avatar kou avatar kjim avatar kazuho avatar ericliang avatar xunzhang avatar xanxys avatar nori0428 avatar mogemimi avatar

Watchers

James Cloos avatar Roy He 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.