zoukankan      html  css  js  c++  java
  • Pomelo的Protobuf

      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
      });
    });
    

     

  • 相关阅读:
    一个表缺失索引发的CPU资源瓶颈案例
    SQLServer 版本之八大方法搞清 "我是谁"
    DBA成长路线
    SQL Server2016升级前几点自检
    SQL Server 2016白皮书
    <译>通过PowerShell工具跨多台服务器执行SQL脚本
    /lib64/libc.so.6: version `GLIBC_2.17' not found
    /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found
    HGT高程数据文件格式解析
    DEM高程数据下载资源
  • 原文地址:https://www.cnblogs.com/fuland/p/4000968.html
Copyright © 2011-2022 走看看