protobufjs是否支持google / protobuf /任何?

问题描述

protobuf.js版本:6.10.1(在节点环境中)

这些是我的源文件

为什么序列化的字节数组不能反序列化?

const request = require('./src/req_pb');
const body = require('./src/body_pb');
const any = require('google-protobuf/google/protobuf/any_pb');

let b = new body.Body();
b.setWord("this is a any example");
let r = new request.Req();
r.setData(new any.Any(b));

let res = r.serializeBinary();
console.log(res);


let ar = request.Req.deserializeBinary(res);

const ab = body.Body.deserializeBinary(ar.getData().getValue());
console.log(ab);
console.log("result:" + ab.getWord());

有我的原始文件

Syntax = "proto3";

message Body {
  string word = 1;
}

Syntax = "proto3";

import "google/protobuf/any.proto";

message Req {
  google.protobuf.Any data = 1;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)