I am working with a Websocket API which I send protobuf objects to.
The documentation says:
Server uses Big Endian format for binary data. Messages sent back and forth require a signed 4 byte int of the message size, prefixed to the message
So the payload should be a 4 byte int which contains the message size, followed by the message itself.
I set the message like this:
const message = req.serializeBinary();
How would I prefix a signed 4 byte int
that contains the message size to this?
Note: console.log(message)
prints the following to the console:
jspb.BinaryReader {decoder_: j…b.BinaryDecoder, fieldCursor_: 0, nextField_: -1, nextWireType_: -1, error_: false, …} decoder_: jspb.BinaryDecoder bytes_: Uint8Array(78) [0, 0, 0, 74, 152, 182, 75, 75, 242, 233, 64, 4, 49, 48, 53, 57, 242, 233, 64, 35, 77, 101, 115, 115, 97, 103, 101, 32, 108, 101, 110, 103, 116, 104, 32, 114, 101, 99, 101, 105, 118, 101, 100, 32, 105, 115, 32, 105, 110, 118, 97, 108, 105, 100, 46, 194, 233, 64, 19, 82, 105, 116, 104, 109, 105, 99, 32, 83, 121, 115, 116, 101, 109, 32, 73, 110, 102, 111] cursor_: 78 end_: 78 error_: false start_: 0 __proto__: Object error_: false fieldCursor_: 55 nextField_: 132760 nextWireType_: 2 readCallbacks_: null
https://stackoverflow.com/questions/65745926/prefix-protobuf-message-with-signed-4-byte-int January 16, 2021 at 10:27AM
没有评论:
发表评论