【发布时间】:2020-04-09 11:55:18
【问题描述】:
我正在尝试使用 protobufjs 中的 encode 方法将消息编码到 Buffer 中。
这是我的代码。
setValue(value) {
var address = makeAddress(value);
let data = protobuf["Icao"].create({data:value})
let container = protobuf["IcaoContainer"].create()
container.entries = data
console.log(container)
var stateEntriesSend = {}
stateEntriesSend[address] = protobuf['IcaoContainer'].encode(container).finish();
console.log(stateEntriesSend[address])
return this.context.setState(stateEntriesSend, this.timeout).then(function(result) {
console.log("Success", result)
}).catch(function(error) {
console.error("Error", error)
})
}
console.log(container) 的值在下方,正确。
IcaoContainer {
entries:
Icao {
data: <Buffer a2 66 61 63 74 69 6f 6e 63 73 65 74 64 64 61 74 61 68 61 73 61 70 6f 69 75 79> } }
但我正在尝试使用 protobuf['IcaoContainer'].encode(container).finish() 将其编码为缓冲区
它似乎返回了一个空缓冲区。 console.log(stateEntriesSend[address]) 的值低于
<Buffer >
我的原型文件。
syntax = "proto3";
message Icao {
string data = 1;
}
message IcaoContainer {
repeated Icao entries = 1;
}
这里有什么问题?
【问题讨论】:
标签: javascript node.js protocol-buffers proto protobuf.js