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

     

  • 相关阅读:
    vim 一些操作
    RedisTemplate 获取过期时间的问题
    SpringBoot 配置 Redis 多缓存名(不同缓存名缓存失效时间不同)
    Vue ElementUI Tree组件 回显问题(设置选择父级时会全选所有的子级,有此业务场景是不适合的)
    动态切换数据库源码解析
    @Primary 注解的作用
    @Value注解的使用
    Shiro&Jwt验证
    浏览器缓存和Service Worker
    Javascript的事件模型和Promise实现
  • 原文地址:https://www.cnblogs.com/fuland/p/4000968.html
Copyright © 2011-2022 走看看