Protobuf js sending a message as byte array

3.3k views Asked by At

Am trying to send a proto3 message in node js and encoding into byte array. however according to protobuf js the message is encoded to buffer (and not byte array) instead in node js. Is there a way of encoding this message to byte array as well?

var message = SomeMessage.create(payload);
var buffer = SomeMessage.encode(messager).finish();
console.log(buffer) // returns <Buffer>
1

There are 1 answers

0
bogdanc On

If you want an array with the numerical values of the bytes you can try:

const bufferedData = Buffer.from(JSON.stringify(message));