在Windows上使用NodeJS的Protobuf [英] Protobuf with NodeJS on Windows

查看:387
本文介绍了在Windows上使用NodeJS的Protobuf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Windows上的NodeJS脚本向设备(Karotz)发送简单的TCP消息。

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


  • NodeJS正确安装工作

  • TCP连接正常工作

  • 这是我的.proto文件(http://wiki.karotz.com/index.php/Voos-message。 proto)

  • 我使用google的protoc将其编译为.desc

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

我不知道如何构建我的消息以将其发送到设备?

I don't know how to build my message to send it to the device ?

  • I read Google Description
  • And protobuff_for_node and other fork

但我不明白如何安装它在窗户上。由于原生图书馆,似乎很复杂。

But I don't understand how to install it on windows. Seems complicated because of native librarie.

是否有简单的javascript图书馆读取.desc Schema并构建消息?没有本机代码或复杂的东西?

Is there dead simple javascript librarie that read the .desc Schema and build the message ? Without native code or complicated stuff ?

推荐答案

如果您正在使用Node.js,那么只使用NPM包版本更简单protobuf库它会为你构建它,假设你的机器上有一个C ++编译器:

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);

protobuf库运行良好且易于使用。但如果您想要一个纯JS版本,请查看: ProtoBufJS

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

这篇关于在Windows上使用NodeJS的Protobuf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆