Tag: 协议缓冲区

在React应用程序中找不到包含npm包的模块

我有一个从API获取一些数据的React应用程序。 数据是过境数据,并与协议缓冲区序列化,所以我使用gtfs-realtime-bindings.js包来反序列化它。 这也使用了ProtoBuf.js和ByteBuffer.js。 但是,当我运行我的开发服务器,我在浏览器中得到这个错误: ./node_modules/protobufjs/ProtoBuf.js Module not found: `/Users/Ben/React/subway- checker/node_modules/ByteBuffer/ByteBuffer.js` does not match the corresponding path on disk `bytebuffer`. 我真的不知道如何开始debugging。 这可能是一个Webpack的问题? 如果有帮助诊断,我正在使用create-react-app。 对于上下文,下面是导致错误的文件中的其余代码: 从'gtfs-realtime-bindings'导入GtfsRealtimeBindings; 从“请求”导入请求; function getFeedData (sub) { var feedId; switch (sub) { case '1' || '2' || '3' || '4' || '5' || '6' || 'S': feedId = 1; break; case 'A' || […]

file upload和谷歌Protobuf

我很难弄清楚如何使用Google协议缓冲区通过WebSocket发送文件。 我的缓冲区的消息结构是 message FileData_m { required uint32 block = 1; // File starting offset required bytes data = 2; // Size of 65536 for blocks } 这个想法是将文件分解成块并通过WebSocket发送。 目前我正在运行一个处理主机和服务器之间的交互的Node.js服务器,我只是不知道如何以二进制方式正确发送文件。 任何帮助和/或指引我在正确的方向将是非常有益的!

错误:字段Message.Field .protobuf.MessageTypeAck.sourceModuleID的非法导线types:1(0预期)

我有应用程序与卡夫卡和协议缓冲profde&消费信息,一切都很好。 我使用SerializeAsString()序列化协议缓冲区(这个应用程序是用c ++编写的)。 现在,我添加了一个新的node.js网站,它也使用消息并尝试解码它们。 我的JS代码(使用伟大的ProtoBuf.js模块): var builder = ProtoBuf.loadProtoFile("/home/aii/general/proto/All.proto"), protobuf = builder.build("protobuf"), Trace = protobuf.Trace, MessageType = protobuf.MessageType, MessageTypeAck = protobuf.MessageTypeAck, MessageTypeKeepAlive = protobuf.MessageTypeKeepAlive; function getMessageType(val) { return Object.keys(MessageType).filter(function(key) {return MessageType[key] === val})[0] } consumer.on('message', function (message) { try{ switch(getMessageType(message.key[0])) { case 'MESSAGE_TYPE_ACK': console.log(MessageTypeAck.decode(message.value)); break; case 'MESSAGE_TYPE_KEEP_ALIVE': console.log(MessageTypeKeepAlive.decode(message.value)); break; default: console.log("Unknown message type"); } } […]

JSON或协议缓冲区来replace自定义TCP消息

本来,我们有两个应用程序与TCP / IP通信,并且它们都是由C ++实现的。 它们之间的消息是自定义消息types。 现在,客户端程序将被改变为基于nodejs web应用程序,并且它们之间的通信将被改变为消息总线,比如rabbitmq 所以它们之间的消息types应该改变。 我首先想到了JSON ,但是自定义消息太复杂了,它们是由template和inheritance来定义的。 看起来,将自定义消息转换为JSON不是一个好的select。 我对吗? class Address { int network; int addressType; //… }; class MsgType{ unsigned char msgSeq; unsigned int msgLen; //… }; class Message{ Address destination; Address source; MsgType msgType; //… }; template <typename T, int RESPONSE_TYPE> class ResponseMessage : public Message{ //… } typedef struct{ […]

Node.js,protobuffer,buffer.lentgh ..如何发送结构化的缓冲区/消息槽tcp?

我写了一个节点/ ssjs程序,使: Tcp连接到数据服务器(Apache MIMA),使用TLS模块。 (好) 通过protobuffer模块对消息进行编码/解码(序列化/反序列化)。(OK) 将序列化的消息发送到服务器并获得响应。 (不好)。 服务器的手册types: Structure of message: [ Length | Header length | Header (| Body length |Body) ] Length – message length = fixed size (4 bytes). Note that this is only the size of following message (not the prefix itself); Header length – fixed size (4 bytes); Header […]

Node.js,协议缓冲区和Ubuntu的 – 如何让它工作?

以下是我用来在node.js中加载一个proto文件的步骤。 总的来说,我如何获得协议缓冲区来处理node.js? 1)将协议缓冲区下载并安装到此位置。 /home/ubuntu/Downloads/protobuf-2.4.1 2)从这个回购下载了这个protobuf-for-node修复。 我将该文件夹放置在我的node.js应用程序文件夹的node_modules文件夹中。 git://github.com/pzgz/protobuf-for-node.git 3)执行以下命令 cd node_modules/protobuf-for-node PROTOBUF=~/Downloads/protobuf-2.4.1 /usr/local/bin/node-waf configure clean build 4)将下列文件移到这些位置: cp node_modules/protobuf-for-node/protobuf_for_node.h /usr/local/include/node cp node_modules/protobuf-for-node/build/Release/protobuf_for_node_lib.so /usr/local/lib 5)执行以下命令来构build随node.js一起提供的feeds.proto示例 cd node_modules/protobuf-for-node/example protoc –descriptor_set_out=feeds.desc –include_imports feeds.proto 6)在应用程序中,我添加了这一行。 var express = require('express'), routes = require('./routes'); var fs = require('fs'); var puts = require('util').puts; url = require('url'); moment = require('moment'); var uuid = require('node-uuid'); […]

Node.js和协议缓冲区 – 如何parsingpost中的PB

我按PB架构加载如下: var Schema = require('protobuf').Schema; var schema = new Schema(fs.readFileSync('/home/ubuntu/workspace/test.desc')); 那么对于一个职位,我期望一个pb,我有以下。 app.post('/mypost', function(req, res){ var Feed = schema['MyRequest']; var aFeed = Feed.parse(req.body); var serialized = Feed.serialize(aFeed); }); 我对node.js比较陌生,也获得了发布数据。 req.body是来自发布数据的缓冲区吗? TypeError: Argument should be a buffer at Function.parse (unknown source) at /home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/bidder.js:71:22 at callbacks (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/express/lib/router/index.js:272:11) at param (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/express/lib/router/index.js:246:11) at pass (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/express/lib/router/index.js:253:5) at Router._dispatch (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/express/lib/router/index.js:280:4) at Object.handle […]

Sails.js socket.io protobuf.js编码错误消息导致错误:浏览器解码时出现“Illegal buffer”

我添加protobuf消息encription到这个例子。 为此我有: Chat.proto package Chat; message Message{ required string user = 1; optional string message = 2; optional string id = 3; } ChatController.js: … var builder = ProtoBuf.loadProtoFile(require('path').resolve(sails.config.appPath, "assets/proto/Chat.proto")), Message = builder.build("Chat").Message; var encodeMessage = function (message) { "use strict"; sails.log.info("WILL ENCODE", message); var msg = new Message(message); sails.log.info("ENCODED", msg); return msg; }; module.exports […]

ProtoBuf.js如何在编码对象时过滤额外的字段

我正在使用Protobuf.js为sails.js编写一个钩子,以便能够通过socket.io发送由协议缓冲区编码的消息。 说我有一个原型schemeMessage.proto : message Message{ required string message = 1; optional string user = 2; optional int32 id = 3; } 我从数据库中获取一个对象作为data : data = { message: 'Hello', user: 'johnDoe', id: 90, createdAt: '2015-10-16T10:15:39.837Z', updatedAt: '2015-10-16T10:15:39.837Z' }; 我有一个代码: var ProtoBuf = require("protobufjs"), Reflect = ProtoBuf.Reflect, builder = ProtoBuf.newBuilder(), protoModels; … // This method overrides socket.io […]

这个protobuffer解码有什么问题?

我正在使用Google protobuffer解码一些缓冲区。 我正在使用优秀的@decodeIO ProtoBuf.js模块。 当我尝试解码这个缓冲区时: <Buffer 0a 0b 47 57 5f 2d 31 38 5f 39 39 32 39> 从这个消息: message PaymentResponseElement { optional int64 pnPaymentId = 1; optional string messageCode = 2; //won't use pb enum here optional int64 balanceAfterTransaction = 3; optional int32 version = 4; } 我得到这个错误: Error: Illegal wire type for […]