protobuf.marshal 用于进行 pb 反序列化。
unmarshal(message: string, data: ArrayBuffer, filename?: string): any
参数
参数 | 类型 | 描述 |
message | string | 结构体名 |
data | ArrayBuffer | 二进制请求体 |
filename? | string | 可选,参数文件名 |
返回
类型 | 描述 |
any | 反序列化得到的结果 |
样例
调用方法进行 pb 反序列化:
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"}}