pomelo的protobuf实现,借助了javascript的动态性,使得应用程序可以在运行时解析proto文件,不需要进行proto文件的编译。pomelo的实现中,为了更方便地解析proto文件,使用了json格式,与原生的proto文件语法是相通的,但是是不相同的。用户定义好客户端以及服务端的通信所需要的信息格式的proto文件,服务端的proto配置放在config/serverProtos.json中,客户端的proto配置放在config/clientProtos.json。如果在其配置文件里,配置了所有类型的proto信息,那么在通信过程中,将会全部使用二进制的方式对消息进行编码; 如果没有定义某一类消息相应的proto,pomelo还是会使用初始的json格式对消息进行编

// clientProtos.json
{
"chat.chatHandler.send": {
"required string rid": 1,
"required string content": 2,
"required string from": 3,
"required string target": 4
}, "connector.entryHandler.enter": {
"required string username": 1,
"required string rid": 2
}, "gate.gateHandler.queryEntry": {
"required string uid": 1
}
} // serverProtos.json
{
"onChat": {
"required string msg": 1,
"required string from": 2,
"required string target": 3
}, "onLeave": {
"required string user": 1
}, "onAdd": {
"required string user": 1
}
}

在app.js中配置:

app.configure('production|development', 'connector',  function() {
app.set('connectorConfig', {
connector: pomelo.connectors.hybridconnector,
heartbeat: 3,
useDict: true,
useProtobuf: true //enable useProtobuf
});
}); app.configure('production|development', 'gate', function(){
app.set('connectorConfig', {
connector : pomelo.connectors.hybridconnector,
useDict: true,
useProtobuf: true //enable useProtobuf
});
});

Pomelo的Protobuf的更多相关文章

  1. pomelo 协议

    分析的是hybridconnector,使用的chatofpomelo-websocket(pomelo为0.7.0) 參考:https://github.com/NetEase/pomelo/wik ...

  2. pomelo RPC调用时新增字段缺失

    接触pomelo开发一个月,正式开始参与项目开发有10天,遇到很多细节的坑,今天讲讲标题:后端服务器节点之间的rpc调用过程中,返回的数据中新增字段缺失问题. 先讲结果:原因是该rpc调用已经采用了p ...

  3. 转: 基于netty+ protobuf +spring + hibernate + jgroups开发的游戏服务端

    from: http://ybak.iteye.com/blog/1853335 基于netty+ protobuf +spring + hibernate + jgroups开发的游戏服务端 游戏服 ...

  4. python通过protobuf实现rpc

    由于项目组现在用的rpc是基于google protobuf rpc协议实现的,所以花了点时间了解下protobuf rpc.rpc对于做分布式系统的人来说肯定不陌生,对于rpc不了解的童鞋可以自行g ...

  5. Protobuf使用规范分享

    一.Protobuf 的优点 Protobuf 有如 XML,不过它更小.更快.也更简单.它以高效的二进制方式存储,比 XML 小 3 到 10 倍,快 20 到 100 倍.你可以定义自己的数据结构 ...

  6. java netty socket库和自定义C#socket库利用protobuf进行通信完整实例

    之前的文章讲述了socket通信的一些基本知识,已经本人自定义的C#版本的socket.和java netty 库的二次封装,但是没有真正的发表测试用例. 本文只是为了讲解利用protobuf 进行C ...

  7. 在Wcf中应用ProtoBuf替代默认的序列化器

    Google的ProtoBuf序列化器性能的牛逼已经有目共睹了,可以把它应用到Socket通讯,队列,Wcf中,身为dotnet程序员一边期待着不久后Grpc对dotnet core的支持更期待着Wc ...

  8. protobuf的编译安装

    github地址:https://github.com/google/protobuf支持多种语言,有多个语言的版本,本文采用的是在centos7下编译源码进行安装. github上有详细的安装说明: ...

  9. 编译protobuf的jar文件

    1.准备工作 需要到github上下载相应的文件,地址https://github.com/google/protobuf/releases protobuf有很多不同语言的版本,因为我们需要的是ja ...

随机推荐

  1. js正则之零宽断言

    我们学到的正则表达式匹配,都是有“宽度”的,使用 \w+. 匹配下面文本,会将 . 一同匹配: regular. expression. 如果不想匹配符号,只匹配一个位置,就要用到“零宽断言”(匹配宽 ...

  2. Javascript 浏览器探测

    1.根据浏览器的性能 var is = { ff: window.globalStorage, ie: document.all && !window.opera, ie6: !win ...

  3. spark 文件系统Alluxio(之前名为Tachyon)

    http://www.alluxio.org/documentation/v1.0.0/cn/ http://www.winseliu.com/blog/2016/04/15/alluxio-quic ...

  4. java SWT嵌入IE,SafeArray .

    java SWT嵌入IE,SafeArray );    // Create a by ref variant    Variant variantByRef = new Variant(pVaria ...

  5. centos 7用ss命令来查看端口占用和对应进程

    mysqld进程在监听4567端口,进程id是2593:# ss -lnp|grep 4567tcp    LISTEN     0      128                    *:456 ...

  6. arcengine C#关于动态添加图层

    动态加载影像图层为例 研究了两三天算是弄出来了.本例适合影像数据量特别的大程序使用,可以动态的添加删除影像数据,还有不完善的地方,不过基本满足要求. 1.首先得到关键点的图层 m_Map = axMa ...

  7. [ERROR] InnoDB: Cannot allocate memory for the buffer pool

    :: mysqld_safe Starting mysqld daemon with databases from /data/mysqldb -- :: [Note] /usr/local/mysq ...

  8. 2、手把手教你Extjs5(二)项目中文件的加载过程

    上一节中用sencha工具自动创建了一个项目,并且可以在浏览器中查看.现在我们来看看js类加载过程.如下图所示: 1、首先:浏览器中输入 localhost:1841 ,调用 index.html; ...

  9. ymodem协议c实现(转)

    源:ymodem协议c实现 /****************************************Copyright (c)******************************** ...

  10. 设计模式笔记之二:Android开发中的MVP架构(转)

    写在前面,本博客来源于公众号文章:http://mp.weixin.qq.com/s?__biz=MzA3MDMyMjkzNg==&mid=402435540&idx=1&sn ...