Protobuf with NodeJS on Windows

杀马特。学长 韩版系。学妹 提交于 2019-12-03 16:35:48

If you're using Node.js it's simpler to just use the NPM package version of the protobuf library it'll build it for you, assuming you have a C++ compiler on your machine:

> npm install protobuf

To build your message & parse and 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 pure JS version, have a look at: ProtoBufJS

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!