Variable defaultConst

default: {
    JCE: "jce";
    PB: "pb";
    invoke(method: string, body: objcet, option: Option): objcet;
    loadDir(importPath?: string): void;
    marshal(message: string, value: objcet, option: Option): ArrayBuffer;
    unmarshal(message: string, data: ArrayBuffer, option: Option): object;
}

Type declaration

  • JCE: "jce"

    JCE 协议。

  • PB: "pb"

    PB 协议。

  • invoke:function
    • 调用方法。

      import protohub from 'pts/protohub';

      protohub.loadDir('RankingRPCServant');

      export default function () {
      const rsp = protohub.invoke('GetRankingResponse', {
      "request": {
      "query": "query"
      },
      }, {
      protocol: 'tars',
      env: 'test',
      serviceName: 'trpc.wtp.demo.tars',
      head: {
      "sFuncName": "GetRankingResponse",
      "iVersion": 1
      }
      });
      console.log(rsp.body.response.retList);
      };

      Parameters

      • method: string

        方法名

      • body: objcet

        请求包

      • option: Option

        Option 对象

      Returns objcet

      响应对象

  • loadDir:function
    • 加载协议文件。

      import protohub from 'pts/protohub';

      protohub.loadDir('RankingRPCServant');

      Parameters

      • OptionalimportPath: string

        协议文件目录。

      Returns void

  • marshal:function
    • 序列化消息。

      import protohub from 'pts/protohub';

      protohub.loadDir('user_logic');

      export default function () {
      let data = protohub.marshal('stGetUserInfoReq', {"person_id": "123456"}, {protocol: protohub.JCE});
      console.log(data); // [object ArrayBuffer]

      let value = protohub.unmarshal('stGetUserInfoReq', data, {protocol: protohub.JCE});
      console.log(JSON.stringify(value));
      // {"extraInfo":{},"medalScene":0,"person_id":"123456","needPrivateInfo":0}
      };

      Parameters

      • message: string

        结构体名

      • value: objcet

        json 格式的消息

      • option: Option

        Option 对象

      Returns ArrayBuffer

      二进制数据

  • unmarshal:function
    • 反序列化消息。

      import protohub from 'pts/protohub';

      protohub.loadDir('user_logic');

      export default function () {
      let data = protohub.marshal('stGetUserInfoReq', {"person_id": "123456"}, {protocol: protohub.JCE});
      console.log(data); // [object ArrayBuffer]

      let value = protohub.unmarshal('stGetUserInfoReq', data, {protocol: protohub.JCE});
      console.log(JSON.stringify(value));
      // {"extraInfo":{},"medalScene":0,"person_id":"123456","needPrivateInfo":0}
      };

      Parameters

      • message: string

        结构体名

      • data: ArrayBuffer

        二进制数据

      • option: Option

        Option 对象

      Returns object

      json 格式的消息