Protobuff with NodeJS on Windows

I would like to send a simple TCP message to a device (Karotz) from NodeJS Script on Windows.

  • NodeJS correctly installed working
  • The TCP connection is working.
  • Here is my .proto file (http://wiki.karotz.com/index.php/Voos-message.proto)
  • I will compile it in .desc using google protoc

I don’t know how to create my message to send it to the device?

But I do not understand how to install it on windows. It seems complicated because of the native library.

Is there a dead simple javascript library that reads a .desc schema and creates a message? Without native code or complex material?

+4
source share
1 answer

If you use Node.js, it’s easier to just use the NPM version of the protobuf library, it will build it for you if you have a C ++ compiler on your computer:

> npm install protobuf 

To create your own message and analyze the existing message:

 var Schema = require('protobuf').Schema; var readFile = require('fs').readFileSync; var schema = new Schema(readFile(__dirname+'/Voos-message.desc')); var VooMsg = schema['net.violet.voos.message.VoosMsg']; // Convert to protobuf format var msg = VooMsg.serialize({id:1, correlationId: 'hello'}); // Read it back var outMsg = VooMag.parse(msg); 

The protobuf library works very well and is easy to use. But if you want a clean version of JS, look at: ProtoBufJS

+2
source

All Articles