[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

编译:

[[email protected] msgpack-c-cpp-2.1.2]# cmake .
[[email protected] msgpack-c-cpp-2.1.2]# make

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

[[email protected] 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
[[email protected] 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
[[email protected] msgpack-c-cpp-2.1.2]# 

ditails

Cmake 指定按照目录

[[email protected] 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>

时间: 2024-08-04 14:35:08

[skill][msgpack] 初试msgpack库以及基本使用的相关文章

【SimpleMsgPack.NET】发布一个msgpack协议C#版本的解析开源库

这两年一直都关注这IOCP在网络通信这方面的应用,当然数据的传递是经常需要的.今年接触了MsgPack格式,发现他用来做传输时数据打包真是太爽了.因为他可以直接打包二进制数据,不需要任何的转换.有人会说自己打包也不是什么难事,是的,没错.但是有标准的格式协议,为什么不直接使用.看了下msgpack的协议格式,压缩基本上做到了最大化.http://msgpack.org可以了解下它的协议格式. 我的主要工作是Delphi进行开发,Delphi里面有qmsgpack.自己也写了一个simpleMsg

重点关注之自定义序列化方式(Protobuf和Msgpack)

除了默认的JSON和XML序列化器外,如果想使用其它格式的(比如二进制)序列化器,也是可以的.比如著名的Protobuf和Msgpack,它们都是二进制的序列化器,特点是速度快,体积小.使用方法如下. 1.定义MediaTypeFormatter,这里以定义MsgPack的formatter为例,主要代码如下. 2.WebApiConfig中注册,代码如下. 3.客户端调用(请求头中指定Accept),在.net端调用使用HttpClient,代码如下图. 附:MessagePackMediaT

ZMQ和MessagePack的简单使用(转)

近段日子在做一个比较复杂的项目,其中用到了开源软件ZMQ和MessagePack.ZMQ对底层网络通信进行了封装,是一个消息处理队列库, 使用起来非常方便.MessagePack是一个基于二进制的对象序列化类库,具有跨语言的特性,同样非常容易使用.在我做的项目中,消息类通过 MessagePack进行压包,然后写入ZMQ的消息结构体,通过ZMQ传递,最后接收者利用MessagePack进行解包,从而分析命令.由于我英 语水平实在不高,所以我并没有通过阅读它们的说明文档来对它们进行了解,而仅仅是通

Rust 优劣势: v.s. C++ / v.s. Go(持续更新)

Rust 发展速度比 C++ 强很多.如果去翻 open-std 的故纸堆,会发现 C++ 这边有很多人(包括标准委员会的人)提了有用的提案,但后来大多不了了之或经历了非常长的时间才进入标准. >> C++ 设计哲学&思想体系 另外就是以前就有的: Rust 有很漂亮的宏和植入类型系统的生命期体系.目前看来 C++ 没什么可能加进去.(虽然有的编译器已经能将生命期诊断实现为警告,但这仍与语言标准本身关系不大) Rust 有更加简洁而规范的对象模型. C++ 可以写出很 weird 的类

mina的编码和解码以及断包的处理,发送自定义协议,仿qq聊天,发送xml或json和

最近一段时间以来,mina很火,和移动开发一样,异常的火爆.前面写了几篇移动开发的文章,都还不错,你们的鼓励就是我最大的动力.好了,废话少说.我们来看下tcp通讯吧. tcp通讯对于java来说是很简单的.就是socket,也就是大家常说的套接字.大家不要把它看的很难.说白了tcp通讯其实就是数据流的读写.一条输入流,一条输出流.分别复杂发消息和接收消息. 明白了这些,ok,我们来看看我写的例子吧.先看服务器端的测试类的源码: package com.minaqq.test; import co

跨平台网络编程

程序员也三年了,工作以来,一直都在写游戏逻辑,刚好最近闲下来,难得有时间,自己研究一些新的东西.因此赶紧看看关于网络方面的东西,总结一下,好记心不如烂键盘. 其实总的来说,网络也就那么回事,比我原本想像中要简单很多,只有简单的几个接口. 一开始关于大数据,我还想复杂了,原本以为需要自己分包,再合包,而且我一开始也是这么做的,都已经做好了,再问别人才发现,这是没有必要的.(伤心!!) 网络就是一个数据流,发送的时候,可以分多次send,接收时,也可以多次recv , 因为有缓存机制. 首先,需要做

window下安装jupyter

1.Install [Anaconda](https://docs.continuum.io/anaconda/install#anaconda-install) 实际上安装了anaconda就已经安装好了jupyter,但是为了便于一些分析,我们配置一些环境. 2.配置环境 conda env create -f environment.yml 其中environment.yml中的内容如下: name: vdl dependencies: - cycler=0.10.0=py35_0 - d

nodejs express 加载html模板

在nodejs中如使用express框架,她默认的是ejs和jade渲染模板.由于我在使用的时候觉得她的代码书写方式很不爽还是想用html的形式去书写,于是我找了使用了html模板. 直接上代码,主要的是在 app.engine('.html', ejs.__express); app.set('view engine', 'html'); 这两句. 1 var http = require('http'), 2 express = require('express'), 3 fs = requ

TRACE nova AttributeError: &#39;module&#39; object has no attribute &#39;packs&#39; 解决办法

I got the following errors when I was deploying OpenStack with devstack. 2013-02-28 01:08:28 DEBUG nova.utils [-] backend <module 'nova.db.sqlalchemy.migration' from '/opt/stack /nova/nova/db/sqlalchemy/migration.pyc'> from (pid=27011) __get_backend