• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

ci/H27-Nov-2017-

erb/v1/H27-Nov-2017-

example/H03-May-2022-

external/boost/H27-Nov-2017-

include/H27-Nov-2017-

src/H27-Nov-2017-

test/H03-May-2022-

.gitignoreH A D27-Nov-2017733

.gitmodulesH A D27-Nov-2017242

.travis.ymlH A D27-Nov-20177.6 KiB

CHANGELOG.mdH A D27-Nov-201713.5 KiB

COPYINGH A D27-Nov-2017200

DoxyfileH A D27-Nov-201763.9 KiB

Files.cmakeH A D27-Nov-201732.8 KiB

NOTICEH A D27-Nov-2017419

QUICKSTART-C.mdH A D27-Nov-20175.2 KiB

QUICKSTART-CPP.mdH A D27-Nov-20173.8 KiB

README.mdH A D27-Nov-20174.8 KiB

appveyor.ymlH A D27-Nov-20172.2 KiB

make_file_list.shH A D27-Nov-2017746

makedist.shH A D27-Nov-20171.5 KiB

msgpack-config.cmake.inH A D27-Nov-2017385

msgpack.pc.inH A D27-Nov-2017238

msgpack_vc8.slnH A D27-Nov-2017891

msgpack_vc8.vcprojH A D27-Nov-20173.8 KiB

preprocessH A D27-Nov-20171 KiB

update_version.shH A D27-Nov-2017743

README.md

1`msgpack` for C/C++
2===================
3
4Version 2.1.5 [![Build Status](https://travis-ci.org/msgpack/msgpack-c.svg?branch=master)](https://travis-ci.org/msgpack/msgpack-c) [![Build status](https://ci.appveyor.com/api/projects/status/8kstcgt79qj123mw/branch/master?svg=true)](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/master)
5
6It's like JSON but small and fast.
7
8Overview
9--------
10
11[MessagePack](http://msgpack.org/) is an efficient binary serialization
12format, which lets you exchange data among multiple languages like JSON,
13except that it's faster and smaller. Small integers are encoded into a
14single byte while typical short strings require only one extra byte in
15addition to the strings themselves.
16
17Example
18-------
19
20In C:
21
22```c
23#include <msgpack.h>
24#include <stdio.h>
25
26int main(void)
27{
28    /* msgpack::sbuffer is a simple buffer implementation. */
29    msgpack_sbuffer sbuf;
30    msgpack_sbuffer_init(&sbuf);
31
32    /* serialize values into the buffer using msgpack_sbuffer_write callback function. */
33    msgpack_packer pk;
34    msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
35
36    msgpack_pack_array(&pk, 3);
37    msgpack_pack_int(&pk, 1);
38    msgpack_pack_true(&pk);
39    msgpack_pack_str(&pk, 7);
40    msgpack_pack_str_body(&pk, "example", 7);
41
42    /* deserialize the buffer into msgpack_object instance. */
43    /* deserialized object is valid during the msgpack_zone instance alive. */
44    msgpack_zone mempool;
45    msgpack_zone_init(&mempool, 2048);
46
47    msgpack_object deserialized;
48    msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized);
49
50    /* print the deserialized object. */
51    msgpack_object_print(stdout, deserialized);
52    puts("");
53
54    msgpack_zone_destroy(&mempool);
55    msgpack_sbuffer_destroy(&sbuf);
56
57    return 0;
58}
59```
60
61See [`QUICKSTART-C.md`](./QUICKSTART-C.md) for more details.
62
63In C++:
64
65```c++
66#include <msgpack.hpp>
67#include <string>
68#include <iostream>
69#include <sstream>
70
71int main(void)
72{
73    msgpack::type::tuple<int, bool, std::string> src(1, true, "example");
74
75    // serialize the object into the buffer.
76    // any classes that implements write(const char*,size_t) can be a buffer.
77    std::stringstream buffer;
78    msgpack::pack(buffer, src);
79
80    // send the buffer ...
81    buffer.seekg(0);
82
83    // deserialize the buffer into msgpack::object instance.
84    std::string str(buffer.str());
85
86    msgpack::object_handle oh =
87        msgpack::unpack(str.data(), str.size());
88
89    // deserialized object is valid during the msgpack::object_handle instance is alive.
90    msgpack::object deserialized = oh.get();
91
92    // msgpack::object supports ostream.
93    std::cout << deserialized << std::endl;
94
95    // convert msgpack::object instance into the original type.
96    // if the type is mismatched, it throws msgpack::type_error exception.
97    msgpack::type::tuple<int, bool, std::string> dst;
98    deserialized.convert(dst);
99
100    return 0;
101}
102```
103
104See [`QUICKSTART-CPP.md`](./QUICKSTART-CPP.md) for more details.
105
106Usage
107-----
108
109### C++ Header Only Library
110
111When you use msgpack on C++03 and C++11, you can just add
112msgpack-c/include to your include path:
113
114    g++ -I msgpack-c/include your_source_file.cpp
115
116If you want to use C version of msgpack, you need to build it. You can
117also install the C and C++ versions of msgpack.
118
119### Building and Installing
120
121#### Install from git repository
122
123##### Using the Terminal (CLI)
124
125You will need:
126
127 - `gcc >= 4.1.0`
128 - `cmake >= 2.8.0`
129
130C and C++03:
131
132    $ git clone https://github.com/msgpack/msgpack-c.git
133    $ cd msgpack-c
134    $ cmake .
135    $ make
136    $ sudo make install
137
138If you want to setup C++11 version of msgpack instead,
139execute the following commands:
140
141    $ git clone https://github.com/msgpack/msgpack-c.git
142    $ cd msgpack-c
143    $ cmake -DMSGPACK_CXX11=ON .
144    $ sudo make install
145
146#### GUI on Windows
147
148Clone msgpack-c git repository.
149
150    $ git clone https://github.com/msgpack/msgpack-c.git
151
152or using GUI git client.
153
154e.g.) tortoise git https://code.google.com/p/tortoisegit/
155
1561. Launch [cmake GUI client](http://www.cmake.org/cmake/resources/software.html).
157
1582. Set 'Where is the source code:' text box and 'Where to build
159the binaries:' text box.
160
1613. Click 'Configure' button.
162
1634. Choose your Visual Studio version.
164
1655. Click 'Generate' button.
166
1676. Open the created msgpack.sln on Visual Studio.
168
1697. Build all.
170
171### Documentation
172
173You can get addtional information on the
174[wiki](https://github.com/msgpack/msgpack-c/wiki).
175
176Contributing
177------------
178
179`msgpack-c` is developed on GitHub at [msgpack/msgpack-c](https://github.com/msgpack/msgpack-c).
180To report an issue or send a pull request, use the
181[issue tracker](https://github.com/msgpack/msgpack-c/issues).
182
183Here's the list of [great contributors](https://github.com/msgpack/msgpack-c/graphs/contributors).
184
185License
186-------
187
188`msgpack-c` is licensed under the Boost Software License, Version 1.0. See
189the [`LICENSE_1_0.txt`](./LICENSE_1_0.txt) file for details.
190