首页 > 代码库 > [skill][msgpack] 初试msgpack库以及基本使用

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

 

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.2]# cmake .
[root@okk msgpack-c-cpp-2.1.2]# make

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

技术分享
[root@okk msgpack-c-cpp-2.1.2]# cmake .
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- 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.2
[root@okk msgpack-c-cpp-2.1.2]# make
Scanning dependencies of target msgpackc
[  4%] Building C object CMakeFiles/msgpackc.dir/src/objectc.c.o
[  8%] Building C object CMakeFiles/msgpackc.dir/src/unpack.c.o
[ 12%] Building C object CMakeFiles/msgpackc.dir/src/version.c.o
[ 16%] Building C object CMakeFiles/msgpackc.dir/src/vrefbuffer.c.o
[ 20%] Building C object CMakeFiles/msgpackc.dir/src/zone.c.o
Linking C shared library libmsgpackc.so
[ 20%] Built target msgpackc
Scanning dependencies of target msgpackc-static
[ 24%] Building C object CMakeFiles/msgpackc-static.dir/src/objectc.c.o
[ 28%] Building C object CMakeFiles/msgpackc-static.dir/src/unpack.c.o
[ 32%] Building C object CMakeFiles/msgpackc-static.dir/src/version.c.o
[ 36%] Building C object CMakeFiles/msgpackc-static.dir/src/vrefbuffer.c.o
[ 40%] Building C object CMakeFiles/msgpackc-static.dir/src/zone.c.o
Linking C static library libmsgpackc.a
[ 40%] Built target msgpackc-static
Scanning dependencies of target lib_buffer_unpack
[ 44%] Building C object example/c/CMakeFiles/lib_buffer_unpack.dir/lib_buffer_unpack.c.o
Linking C executable lib_buffer_unpack
[ 44%] Built target lib_buffer_unpack
Scanning dependencies of target simple_c
[ 48%] Building C object example/c/CMakeFiles/simple_c.dir/simple_c.c.o
Linking C executable simple_c
[ 48%] Built target simple_c
Scanning dependencies of target speed_test_uint32_array
[ 52%] Building C object example/c/CMakeFiles/speed_test_uint32_array.dir/speed_test_uint32_array.c.o
Linking C executable speed_test_uint32_array
[ 52%] Built target speed_test_uint32_array
Scanning dependencies of target speed_test_uint64_array
[ 56%] Building C object example/c/CMakeFiles/speed_test_uint64_array.dir/speed_test_uint64_array.c.o
Linking C executable speed_test_uint64_array
[ 56%] Built target speed_test_uint64_array
Scanning dependencies of target user_buffer_unpack
[ 60%] Building C object example/c/CMakeFiles/user_buffer_unpack.dir/user_buffer_unpack.c.o
Linking C executable user_buffer_unpack
[ 60%] Built target user_buffer_unpack
Scanning dependencies of target class_intrusive
[ 64%] Building CXX object example/cpp03/CMakeFiles/class_intrusive.dir/class_intrusive.cpp.o
Linking CXX executable class_intrusive
[ 64%] Built target class_intrusive
Scanning dependencies of target class_intrusive_map
[ 68%] Building CXX object example/cpp03/CMakeFiles/class_intrusive_map.dir/class_intrusive_map.cpp.o
Linking CXX executable class_intrusive_map
[ 68%] Built target class_intrusive_map
Scanning dependencies of target class_non_intrusive
[ 72%] Building CXX object example/cpp03/CMakeFiles/class_non_intrusive.dir/class_non_intrusive.cpp.o
Linking CXX executable class_non_intrusive
[ 72%] Built target class_non_intrusive
Scanning dependencies of target custom
[ 76%] Building CXX object example/cpp03/CMakeFiles/custom.dir/custom.cpp.o
Linking CXX executable custom
[ 76%] Built target custom
Scanning dependencies of target enum
[ 80%] Building CXX object example/cpp03/CMakeFiles/enum.dir/enum.cpp.o
Linking CXX executable enum
[ 80%] Built target enum
Scanning dependencies of target map_based_versionup
[ 84%] Building CXX object example/cpp03/CMakeFiles/map_based_versionup.dir/map_based_versionup.cpp.o
Linking CXX executable map_based_versionup
[ 84%] Built target map_based_versionup
Scanning dependencies of target protocol_new
[ 88%] Building CXX object example/cpp03/CMakeFiles/protocol_new.dir/protocol_new.cpp.o
Linking CXX executable protocol_new
[ 88%] Built target protocol_new
Scanning dependencies of target reuse_zone
[ 92%] Building CXX object example/cpp03/CMakeFiles/reuse_zone.dir/reuse_zone.cpp.o
Linking CXX executable reuse_zone
[ 92%] Built target reuse_zone
Scanning dependencies of target simple
[ 96%] Building CXX object example/cpp03/CMakeFiles/simple.dir/simple.cpp.o
Linking CXX executable simple
[ 96%] Built target simple
Scanning dependencies of target stream
[100%] Building CXX object example/cpp03/CMakeFiles/stream.dir/stream.cpp.o
Linking CXX executable stream
[100%] Built target stream
[root@okk msgpack-c-cpp-2.1.2]# 
ditails

 

Cmake 指定按照目录

[root@okk msgpack-c-cpp-2.1.2]# 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

 

举个栗子:

  TODO: <url for my github>

 

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