我终于找到了这个问题的答案,只是通过查看该的NodeJS图书馆浪费了大量的时间之后。
//SERIALIZATION:
var buffer = new Buffer(notification);
var transport = new thrift.TFramedTransport(buffer);
var binaryProt = new thrift.TBinaryProtocol(transport);
notification.write(binaryProt);
此时,字节阵列可在transport.outBuffers字段中找到:
var byteArray = transport.outBuffers;
对于反序列化:
var tTransport = new thrift.TFramedTransport(byteArray);
var tProtocol = new thrift.TBinaryProtocol(tTransport);
var receivedNotif = new notification_type.Notification();
receivedNotif.read(tProtocol);
此外以下行需要被添加到从库的NodeJS的index.js文件节俭:
exports.TFramedTransport = require('./transport').TFramedTransport;
exports.TBufferedTransport = require('./transport').TBufferedTransport;
exports.TBinaryProtocol = require('./protocol').TBinaryProtocol;
另外还有在图书馆的NodeJS至少一个错误。
对不起,但您在同一个脚本中反序列化了已创建的相同数据。但是如果使用一些中间存储器(rabbitmq)在兔子里存储什么数据?切出缓冲区?或者每次调用flush并在回调中保存数据?并且对于byteArray使用片并不是每次都是好主意,因为它不复制数据,而是参考它。 – Selvatico