- 浏览: 53343 次
- 性别:
- 来自: 北京
-
最新评论
-
lehehe:
基站定位,使用接口很方便的,这里有免费的接口,你可以试试,ht ...
google API基站定位 -
donkeyji:
yongqi 写道hi,你好,请教一个问题我在安装python ...
python zeromq 介绍 -
yongqi:
hi,你好,请教一个问题我在安装python的zeromq包时 ...
python zeromq 介绍 -
mimicom:
看着晕乎乎的....
python zeromq 介绍 -
raojl:
不错,好像zeromq就在2011年一夜之间火了,特别的blo ...
python zeromq 介绍
Cmake是一套跨平台的工程构建工具
sudo apt-get install cmake
一个Cmake的例子
生成一个demo工程,包括一个hello.cpp文件(在demo工程下)
#include <stdio.h> int main(int argc, char **argv) { printf("Hello world!\n"); return 0; }
Cmake构建该工程
Cmake需要CMakeLists.txt文件来配置,在demo目录下创建CMakeLists.txt文件
PROJECT (Test) SET(SRC_LIST hello.cpp) ADD_EXECUTABLE(test ${SRC_LIST})
构建项目
cmake .
便会生成相应的Makefile文件
Protobuf
安装protobuf-c
需要先安装google protobuf
http://code.google.com/p/protobuf/downloads/list
./configure
make
make check
make install
下载
http://code.google.com/p/protobuf-c/downloads/list
./configure --prefix=$HOME/install
make
make install
A typical reason for this behaviour is a stale ld.so.cache; try to run ldconfig to update it after making sure that /usr/local/lib is listed in /etc/ld.so.conf.
make不过时可能需要执行 ldconfig 命令
To install into /usr like a normal package would, use --prefix=/usr
protobuf-c Simple complete example
protobuf-c works by taking a.proto file, and generating both .h and .c files for use in C programs.
amessage.proto
message AMessage { required int32 a=1; optional int32 b=2; }
Generate .h and .c files from the command-line in your current working directory:
protoc-c --c_out=. amessage.proto
Serialize/pack Deserialize/upack the AMessage as follows:
amessage_demo.c
#include <stdio.h> #include <stdlib.h> #include "amessage.pb-c.h" int main (int argc, const char * argv[]) { AMessage msg = AMESSAGE__INIT; // AMessage AMessage *rmsg; void *buf; // Buffer to store serialized data unsigned len; // Length of serialized data if (argc != 2 && argc != 3) { // Allow one or two integers fprintf(stderr,"usage: amessage a [b]\n"); return 1; } msg.a = atoi(argv[1]); // Put an int in msg if (argc == 3) { msg.has_b = 1; msg.b = atoi(argv[2]); } // Add another len = amessage__get_packed_size(&msg); // This is calculated packing length buf = malloc(len); // Allocated memory for packed/encode serialized data amessage__pack(&msg,buf); // Put it in buf now fprintf(stderr,"Writing %d serialized bytes\n",len); // See the length of message fwrite(buf,len,1,stdout); // Write to stdout to allow direct command line piping rmsg = amessage__unpack(NULL, len, buf); printf("Received: a=%d", rmsg->a); printf(" b=%d", rmsg->b); printf("\n"); amessage__free_unpacked(rmsg, NULL); free(buf); // Free the allocated serialized buffer return 0; }
编译:
gcc amessage_demo.c amessage.pb-c.c -o amessage_demo -lprotobuf-c
效果:
./amessage_demo 10 2
Writing: 4 serialized bytes
Received: a=10 b=2
安装protobuf-python环境:
cd protobuf目录下python目录
python setup.py install
Protobuf-c RPC service and Protobuf python client
首先写一个结构,重点是加上service这样会生成相应的service方法
rpc.proto
package demo; message SearchRequest { required string keyword = 1; } message SearchResponse { required string result = 1; } service RpcService { rpc Search (SearchRequest) returns (SearchResponse); }
在service中要实现的方法
ProtobufCService *protbuf_c_rpc_client_new
ProtobufC_RPC_Server *protobuf_c_rpc_server_new
python实现protobuf rpc
protobuf-socket-rpc
python protobuf rpc using tcp/ip sockets
http://code.google.com/p/protobuf-socket-rpc/downloads/list
在源码中有实例
Note: 在.proto文件中加入
option py_generic_services = true;
ruby实现protobuf rpc
gem install ruby_protobuf
rpc.proto
package demo; message SearchRequest { required string keyword = 1; } message SearchResponse { required string result = 1; } service RpcService { rpc Search (SearchRequest) returns (SearchResponse); }
rproto rpc.proto
rpc_service.rb
require 'rubygems' require 'protobuf/rpc/server' require 'protobuf/rpc/handler' require 'rpc.pb' class Demo::SearchHandler < Protobuf::Rpc::Handler request Demo::SearchRequest response Demo::SearchResponse def self.process_request(request, response) if request.keyword == 'google' response.result = 'www.google.com' elsif request.keyword == 'freewheel' response.result = 'www.freewheel.tv' else response.result = '' end end end class Demo::RpcService < Protobuf::Rpc::Server def setup_handlers @handlers = { :search => Demo::SearchHandler, } end end
client_search.rb
#!/usr/bin/env ruby require 'rubygems' require 'protobuf/rpc/client' require 'rpc.pb' # build request request1 = Demo::SearchRequest.new request1.keyword = 'google' request2 = Demo::SearchRequest.new request2.keyword = 'freewheel' # create blunk response response1 = Demo::SearchResponse.new response2 = Demo::SearchResponse.new # execute rpc Protobuf::Rpc::Client.new('localhost', 9999).call :search, request1, response1 Protobuf::Rpc::Client.new('localhost', 9999).call :search, request2, response2 p response1.result p response2.result
ruby start_rpc_service
ruby client_search.rb
未完成...
ps:
http://code.google.com/p/protobuf/
发表评论
-
rails model best practices
2011-05-11 09:50 0name_scope :active, :conditions ... -
Ruby标准库
2011-05-10 15:02 0ruby标准库一览 文本 base64 yaml ... -
rails3测试理解
2011-04-30 10:23 1378Why RSpec? Clear, concise and ... -
linux系统备注
2011-04-29 10:49 1203bin "Essential binaries&qu ... -
vim备注
2011-04-29 10:03 0vim -
ruby
2011-04-28 10:33 1106Ruby编程基础知识概括: 1. ruby is an ob ... -
Javascript简明手册
2011-04-25 10:07 0Javascript和C++,java,Python一样是一种 ... -
KVM
2011-04-24 09:36 01 kvm安装 前期准备 ... -
Jquery
2011-04-22 16:10 01. jQuery解决了什么样的问题? -
CSS相关知识
2011-04-22 16:02 7531. CSS是一种为结构化文档添加样式的计算机语言 使 ... -
Mysql相关知识
2011-04-22 14:30 11951. Mysql常规使用 安装 server: sudo ... -
PF_RING
2011-04-14 14:38 20841. PF_RING 安装 A clean insta ... -
thrift实践
2011-04-08 11:52 15121 安装thrift 通过svn获得源码 svn co h ... -
清除历史记录
2011-03-18 10:40 01. 选型 [语言] C++ [平台] wind ... -
pyzmq 使用
2011-03-16 16:02 51381. The Socket API Creating an ... -
nginx X-Accel-Redirect实现文件下载权限控制及rails devise实现
2011-03-14 13:52 3360问题1:Nginx的X-Accel-Redirect? 答: ... -
python zeromq 介绍
2011-03-10 10:38 11184简介: ZeroMQ并不是一个对socket的封装,不能用它 ... -
fabric自动部署
2011-03-09 14:00 2641Fabric commands run - run a ... -
nagios的工作场景及使用说明
2011-03-08 10:15 2075问题1:nagios配置文件说明? 答: comman ... -
在ubuntu下安装nagios监控平台
2011-03-07 16:56 1613问题1:Nagios是什么? 答:是一个监视系统运行状态和网 ...
相关推荐
当你有一个.proto文件,你可以使用protobuf编译器生成对应语言(如C++、Java、Python等)的源代码,这些源代码提供了方便的方法来序列化和反序列化你的数据结构。在C++中,这通常涉及使用`SerializeToString()`和`...
protobuf-2.5.0是Google开发的一种高效、灵活的数据序列化协议,全称为Protocol Buffers。这个版本的下载提供了一个方便的方式,让开发者能够直接获取并安装这一强大的工具,同时还附带了安装教程,帮助用户顺利进行...
总之,`vs2015-protobuf`是一个关于如何在Visual Studio 2015环境下构建和使用Protocol Buffers开源库的指南,涉及到的知识点包括protobuf的序列化协议、CMake构建系统、以及在Windows平台上使用VS2015进行C++项目...
C++ Protobuf,全称为Protocol Buffers,是Google开发的一种数据序列化协议。它提供了一种高效、灵活且语言中立的方式,用于在各种应用程序之间存储和交换数据。C++ Protobuf是其在C++语言环境下的实现,允许开发者...
此外,通过`-DCMAKE_INSTALL_PREFIX`可以自定义Caffe2的安装路径,这对于管理不同版本或不同配置的Caffe2非常有用。通过这种方式,可以在不同的项目中灵活选择所需的Caffe2版本或配置。 #### 六、总结 通过上述...
GRPC 是一个高性能、开源和通用的 RPC 框架,它基于 Google 的 Protocol Buffers(protobuf)协议,用于构建微服务和分布式系统。在本文中,我们将详细探讨 GRPC v1.54.0-dev 版本,以及如何在 Visual Studio 2019 x...
这通常包括gRPC的依赖库,如protobuf(协议缓冲区)和OpenSSL等。因此,我们要了解如何安装和管理这些依赖项。 首先,我们需要确保系统上安装了必要的构建工具,例如GCC编译器、Make、CMake以及Git,因为gRPC的源...