I am trying to send a message over MQTT making use of the google protocol buffer in javascript (ProtoBuf.js)
I was able to encode the message using the following code:
var ProtoBuf = dcodeIO.ProtoBuf;
var builder = ProtoBuf.loadProtoFile("./complex.proto"),
Game = builder.build("Game"),
Car = Game.Cars.Car;
var car = new Car({
"model" : "Rusty",
"vendor" : {
"name" : "Iron Inc.",
"address" : {
"country" : "USa"
}
},
"speed" : "FAST"
});
var buffer = car.encode();
console.log(buffer);
var messagegpb = buffer.toBuffer();
console.log(messagegpb ); //This prints "ArrayBuffer { byteLength: 29 }"
Now for decoding when I tried the following, it just doesn't do anything. I see no logs in the browser as well.
var dec = builder.build("Game"); //nothing after this line gets executed
var msg = dec.decode(messagegpb);
console.log(msg);
This is the link of the .proto file I am using. https://github.com/dcodeIO/ProtoBuf.js/blob/master/tests/complex.proto
Could someone point me where I am going wrong?
Thanks a ton