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

     

  • 相关阅读:
    【BZOJ1076】[SCOI2008]奖励关 状压DP+期望
    【TYVJ1864】[Poetize I]守卫者的挑战 概率与期望
    【BZOJ1426】收集邮票 期望
    设置SAPgui自动退出功能
    SAP系统联机应用程序帮助
    c++ 类型安全
    生成与重新生成的区别
    2014-02-20
    新公司工作
    落后了
  • 原文地址:https://www.cnblogs.com/fuland/p/4000968.html
Copyright © 2011-2022 走看看