123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- `msgpack` for C/C++
- ===================
- Version 3.1.1 [
- {
-
- msgpack_sbuffer sbuf;
- msgpack_sbuffer_init(&sbuf);
-
- msgpack_packer pk;
- msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
- msgpack_pack_array(&pk, 3);
- msgpack_pack_int(&pk, 1);
- msgpack_pack_true(&pk);
- msgpack_pack_str(&pk, 7);
- msgpack_pack_str_body(&pk, "example", 7);
-
-
- msgpack_zone mempool;
- msgpack_zone_init(&mempool, 2048);
- msgpack_object deserialized;
- msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized);
-
- msgpack_object_print(stdout, deserialized);
- puts("");
- msgpack_zone_destroy(&mempool);
- msgpack_sbuffer_destroy(&sbuf);
- return 0;
- }
- ```
- See [`QUICKSTART-C.md`](./QUICKSTART-C.md) for more details.
- In C++:
- ```c++
- #include <msgpack.hpp>
- #include <string>
- #include <iostream>
- #include <sstream>
- int main(void)
- {
- msgpack::type::tuple<int, bool, std::string> src(1, true, "example");
-
-
- std::stringstream buffer;
- msgpack::pack(buffer, src);
-
- buffer.seekg(0);
-
- std::string str(buffer.str());
- msgpack::object_handle oh =
- msgpack::unpack(str.data(), str.size());
-
- msgpack::object deserialized = oh.get();
-
- std::cout << deserialized << std::endl;
-
-
- msgpack::type::tuple<int, bool, std::string> dst;
- deserialized.convert(dst);
-
- msgpack::type::tuple<int, bool, std::string> dst2 =
- deserialized.as<msgpack::type::tuple<int, bool, std::string> >();
- return 0;
- }
- ```
- See [`QUICKSTART-CPP.md`](./QUICKSTART-CPP.md) for more details.
- Usage
- -----
- ### C++ Header Only Library
- When you use msgpack on C++, you can just add
- msgpack-c/include to your include path:
- g++ -I msgpack-c/include your_source_file.cpp
- If you want to use C version of msgpack, you need to build it. You can
- also install the C and C++ versions of msgpack.
- ### Building and Installing
- #### Install from git repository
- ##### Using the Terminal (CLI)
- You will need:
- - `gcc >= 4.1.0`
- - `cmake >= 2.8.0`
- C and C++03:
- $ git clone https:
- $ cd msgpack-c
- $ cmake .
- $ make
- $ sudo make install
- If you want to setup C++11 or C++17 version of msgpack instead,
- execute the following commands:
- $ git clone https:
- $ cd msgpack-c
- $ cmake -DMSGPACK_CXX[11|17]=ON .
- $ sudo make install
- `MSGPACK_CXX[11|17]` flags are not affected to installing files. Just switching test cases. All files are installed in every settings.
- When 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_L
- #### GUI on Windows
- Clone msgpack-c git repository.
- $ git clone https:
- or using GUI git client.
- e.g.) tortoise git https:
- 1. Launch [cmake GUI client](http:
- 2. Set 'Where is the source code:' text box and 'Where to build
- the binaries:' text box.
- 3. Click 'Configure' button.
- 4. Choose your Visual Studio version.
- 5. Click 'Generate' button.
- 6. Open the created msgpack.sln on Visual Studio.
- 7. Build all.
- ### Documentation
- You can get additional information including the tutorial on the
- [wiki](https:
- Contributing
- ------------
- `msgpack-c` is developed on GitHub at [msgpack/msgpack-c](https:
- To report an issue or send a pull request, use the
- [issue tracker](https:
- Here's the list of [great contributors](https:
- License
- -------
- `msgpack-c` is licensed under the Boost Software License, Version 1.0. See
- the [`LICENSE_1_0.txt`](./LICENSE_1_0.txt) file for details.
|