计费概述
按量计费(后付费)
购买方式
欠费说明
退费说明
marshal(message: string, value: any): ArrayBuffer
参数 | 类型 | 描述 |
message | string | 结构体名 |
value | any | JSON 化的请求体 |
类型 | 描述 |
ArrayBuffer | 序列化得到的二进制请求体 |
import protobuf from 'pts/protobuf';// 加载协议文件根目录中的 demo.protoprotobuf.load([], 'demo.proto');// 加载中协议文件 dirName 目录中的 demo.proto// protobuf.load(['dirName'], 'demo.proto');export default function () {// 调用 marshal 进行序列化const data = protobuf.marshal('xxxx.xxx.demo.stSayHelloReq', { msg: 'pts' });console.log(data); // [object ArrayBuffer]// 调用 unmarshal 进行反序列化const value = protobuf.unmarshal('xxxx.xxx.demo.stSayHelloReq', data);console.log(JSON.stringify(value)); // {"msg":"pts"}}
文档反馈