[skill][msgpack] 初试msgpack库以及基本使用

时间:2021-10-14 14:06:08

It's like JSON.   
but fast and small.

http://msgpack.org/index.html

源码:

https://github.com/msgpack/msgpack-c

扩展阅读:

  用到了Cmake ,大概是一个用来生成makefile的系统 :https://cmake.org/overview/

  https://zh.wikibooks.org/zh/CMake_%E5%85%A5%E9%96%80/%E8%BC%B8%E5%87%BA%E4%BD%8D%E7%BD%AE%E8%88%87%E5%AE%89%E8%A3%9D

release:

cpp-2.1.2

呃! 搞了半天也不知道如何用git 把一个tag down下来。有点糗。。。。

直接download zip文件: file:///home/tong/Downloads/msgpack-c-cpp-2.1.2.zip

对应的文档:

  https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_overview

编译:

[root@okk msgpack-c-cpp-2.1.]# cmake .
[root@okk msgpack-c-cpp-2.1.]# make

哇塞,竟然有进度百分比,我也要这样的makefile。0.0 -.-   ~O.O~

[root@okk msgpack-c-cpp-2.1.]# cmake .
-- The C compiler identification is GNU 4.4.
-- The CXX compiler identification is GNU 4.4.
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.3")
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Performing Test MSGPACK_ENABLE_GCC_CXX_ATOMIC
-- Performing Test MSGPACK_ENABLE_GCC_CXX_ATOMIC - Failed
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Configuring done
-- Generating done
-- Build files have been written to: /root/src/thirdparty/github/msgpack-c-cpp-2.1.
[root@okk msgpack-c-cpp-2.1.]# make
Scanning dependencies of target msgpackc
[ %] Building C object CMakeFiles/msgpackc.dir/src/objectc.c.o
[ %] Building C object CMakeFiles/msgpackc.dir/src/unpack.c.o
[ %] Building C object CMakeFiles/msgpackc.dir/src/version.c.o
[ %] Building C object CMakeFiles/msgpackc.dir/src/vrefbuffer.c.o
[ %] Building C object CMakeFiles/msgpackc.dir/src/zone.c.o
Linking C shared library libmsgpackc.so
[ %] Built target msgpackc
Scanning dependencies of target msgpackc-static
[ %] Building C object CMakeFiles/msgpackc-static.dir/src/objectc.c.o
[ %] Building C object CMakeFiles/msgpackc-static.dir/src/unpack.c.o
[ %] Building C object CMakeFiles/msgpackc-static.dir/src/version.c.o
[ %] Building C object CMakeFiles/msgpackc-static.dir/src/vrefbuffer.c.o
[ %] Building C object CMakeFiles/msgpackc-static.dir/src/zone.c.o
Linking C static library libmsgpackc.a
[ %] Built target msgpackc-static
Scanning dependencies of target lib_buffer_unpack
[ %] Building C object example/c/CMakeFiles/lib_buffer_unpack.dir/lib_buffer_unpack.c.o
Linking C executable lib_buffer_unpack
[ %] Built target lib_buffer_unpack
Scanning dependencies of target simple_c
[ %] Building C object example/c/CMakeFiles/simple_c.dir/simple_c.c.o
Linking C executable simple_c
[ %] Built target simple_c
Scanning dependencies of target speed_test_uint32_array
[ %] Building C object example/c/CMakeFiles/speed_test_uint32_array.dir/speed_test_uint32_array.c.o
Linking C executable speed_test_uint32_array
[ %] Built target speed_test_uint32_array
Scanning dependencies of target speed_test_uint64_array
[ %] Building C object example/c/CMakeFiles/speed_test_uint64_array.dir/speed_test_uint64_array.c.o
Linking C executable speed_test_uint64_array
[ %] Built target speed_test_uint64_array
Scanning dependencies of target user_buffer_unpack
[ %] Building C object example/c/CMakeFiles/user_buffer_unpack.dir/user_buffer_unpack.c.o
Linking C executable user_buffer_unpack
[ %] Built target user_buffer_unpack
Scanning dependencies of target class_intrusive
[ %] Building CXX object example/cpp03/CMakeFiles/class_intrusive.dir/class_intrusive.cpp.o
Linking CXX executable class_intrusive
[ %] Built target class_intrusive
Scanning dependencies of target class_intrusive_map
[ %] Building CXX object example/cpp03/CMakeFiles/class_intrusive_map.dir/class_intrusive_map.cpp.o
Linking CXX executable class_intrusive_map
[ %] Built target class_intrusive_map
Scanning dependencies of target class_non_intrusive
[ %] Building CXX object example/cpp03/CMakeFiles/class_non_intrusive.dir/class_non_intrusive.cpp.o
Linking CXX executable class_non_intrusive
[ %] Built target class_non_intrusive
Scanning dependencies of target custom
[ %] Building CXX object example/cpp03/CMakeFiles/custom.dir/custom.cpp.o
Linking CXX executable custom
[ %] Built target custom
Scanning dependencies of target enum
[ %] Building CXX object example/cpp03/CMakeFiles/enum.dir/enum.cpp.o
Linking CXX executable enum
[ %] Built target enum
Scanning dependencies of target map_based_versionup
[ %] Building CXX object example/cpp03/CMakeFiles/map_based_versionup.dir/map_based_versionup.cpp.o
Linking CXX executable map_based_versionup
[ %] Built target map_based_versionup
Scanning dependencies of target protocol_new
[ %] Building CXX object example/cpp03/CMakeFiles/protocol_new.dir/protocol_new.cpp.o
Linking CXX executable protocol_new
[ %] Built target protocol_new
Scanning dependencies of target reuse_zone
[ %] Building CXX object example/cpp03/CMakeFiles/reuse_zone.dir/reuse_zone.cpp.o
Linking CXX executable reuse_zone
[ %] Built target reuse_zone
Scanning dependencies of target simple
[ %] Building CXX object example/cpp03/CMakeFiles/simple.dir/simple.cpp.o
Linking CXX executable simple
[ %] Built target simple
Scanning dependencies of target stream
[%] Building CXX object example/cpp03/CMakeFiles/stream.dir/stream.cpp.o
Linking CXX executable stream
[%] Built target stream
[root@okk msgpack-c-cpp-2.1.]#

ditails

Cmake 指定按照目录

[root@okk msgpack-c-cpp-2.1.]# cmake CMakeLists.txt -DCMAKE_INSTALL_PREFIX=/root/output/

API:  http://c.msgpack.org/c/index.html

api的 packing 用法:

https://github.com/msgpack/msgpack-c/wiki/v2_0_c_overview#packing

api的 unpack 用法:

https://github.com/msgpack/msgpack-c/wiki/v2_0_c_overview#unpack

举个栗子:

                cmake -DCMAKE_INSTALL_PREFIX=$INS_PATH
make
make install