使用带符号的 4 字节 int 前缀 protobuf 消息

问题描述

我正在使用 Websocket API,我将 protobuf 对象发送到该 API。

文档说:

服务器对二进制数据使用 Big Endian 格式。 来回发送的消息需要消息大小的有符号 4 字节整数,以消息为前缀

因此有效负载应该是一个 4 字节的 int,其中包含消息大小,然后是消息本身。

我这样设置消息:

const message = req.serializeBinary();

如何为包含消息大小的 signed 4 byte int 添加前缀?

注意:console.log(message) 将以下内容打印到控制台:

jspb.BinaryReader {decoder_: j…b.BinaryDecoder,fieldCursor_: 0,nextField_: -1,nextWireType_: -1,error_: false,…}
decoder_: jspb.BinaryDecoder
bytes_: Uint8Array(78) [0,74,152,182,75,242,233,64,4,49,48,53,57,35,77,101,115,97,103,32,108,110,116,104,114,99,105,118,100,46,194,19,82,109,83,121,73,102,111]
cursor_: 78
end_: 78
error_: false
start_: 0
__proto__: Object
error_: false
fieldCursor_: 55
nextField_: 132760
nextWireType_: 2
readCallbacks_: null

解决方法

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

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

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