Below is my code for trying to parse a protocol buffer from node.js. It works in python but in node.js I seem to be having issues. My big concern is am 1) am i getting the payload correct? and 2) Am I using protocol buffers to parse the payload correct.
When I log to the console the payload is sys so I am assuming that s the prot buffer from the request. Then I parse the buffer by calling:
bid_request.parse(payload);
Here is the code snippet and error:
var buffertools = require('buffertools');
var Schema = require('protobuf').Schema;
var schema = new Schema(fs.readFileSync('/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/test.desc'));
app.post('/n/test', function(req, res){
var payload = [];
req.on('data', function (data) {
payload.push(data);
});
console.log(payload);
req.on('end', function () {
var payload = buffertools.concat.apply(null, payload);
console.log(payload);
console.log('--------------');
var bid_request = schema['BidRequest'];
var brr_fu = bid_request.parse(payload);
// rest of code here
});
});
libprotobuf ERROR google/protobuf/message_lite.cc:123] Can't parse message of type "BidRequest" because it is missing required fields: id
undefined:1
urn f.call(self,
^
Error: Malformed message
at Function.parse (unknown source)
at IncomingMessage.<anonymous> (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/bidder.js:80:31)
at IncomingMessage.emit (events.js:64:17)
at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:130:23)
at Socket.ondata (http.js:1506:22)
at TCP.onread (net.js:374:27)
I am also curious as to why the payload is a <SlowBuffer>