在仅仅通过查看 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 库中也至少存在一个错误。