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

..03-May-2022-

.github/H05-Jun-2020-425398

ci/H05-Jun-2020-223166

cmake/H05-Jun-2020-5642

erb/v1/H05-Jun-2020-1,006868

example/H03-May-2022-3,4272,580

external/boost/H05-Jun-2020-

fuzz/H03-May-2022-7560

include/H05-Jun-2020-100,15079,069

src/H05-Jun-2020-1,6831,350

test/H03-May-2022-15,28912,887

.gitignoreH A D05-Jun-2020733 5247

.gitmodulesH A D05-Jun-2020242 76

CHANGELOG.mdH A D05-Jun-202016.6 KiB413327

COPYINGH A D05-Jun-2020200 64

DoxyfileH A D05-Jun-202063.9 KiB1,5531,111

Files.cmakeH A D05-Jun-202037.2 KiB763759

NOTICEH A D05-Jun-2020419 1511

QUICKSTART-C.mdH A D05-Jun-20205 KiB192142

QUICKSTART-CPP.mdH A D05-Jun-20203.8 KiB160119

README.mdH A D05-Jun-20205.5 KiB199134

appveyor.ymlH A D05-Jun-20202.2 KiB6359

codecov.ymlH A D05-Jun-2020455 3731

make_file_list.shH A D05-Jun-20201.5 KiB4939

makedist.shH A D05-Jun-20201.6 KiB4333

msgpack-config.cmake.inH A D05-Jun-2020320 2117

msgpack.pc.inH A D05-Jun-2020238 119

msgpack_vc8.slnH A D05-Jun-2020891 2119

msgpack_vc8.vcprojH A D05-Jun-20203.8 KiB188187

preprocessH A D05-Jun-20201 KiB2420

update_version.shH A D05-Jun-2020743 1812

README.md

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