我正在尝试做一个简单的thrift序列化/反序列化但是如果我的反序列化失败,则显示以下消息:
/home/przemek/workspace/leviathan/node_modules/thrift/lib/thrift/protocol.js:350
throw Error("Invalid type: " + type);
^
Error: Invalid type:
at Error (unknown source)
at TBinaryProtocol.skip (/home/przemek/workspace/leviathan/node_modules/thrift/lib/thrift/protocol.js:350:13)
at Object.Profile.read (/home/przemek/workspace/leviathan/gen-nodejs/Profile_types.js:49:15)
at deserialize (/home/przemek/workspace/leviathan/client.js:43:13)
at /home/przemek/workspace/leviathan/client.js:51:2
at serialize (/home/przemek/workspace/leviathan/client.js:35:3)
at Object.<anonymous> (/home/przemek/workspace/leviathan/client.js:49:1)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
我不明白为什么会这样。对我来说,这个错误消息听起来像是错误的类型,但我的序列化工作,所以序列化的对象应该具有正确的类型。执行TBinaryProtocol.prototype.skip时,protocol.js文件会抛出此错误。这是我的代码:
function serialize(data, callback) {
var buffer = new Buffer(data);
var transport = new thrift.TFramedTransport(buffer);
var protocol = new thrift.TBinaryProtocol(transport);
data.write(protocol);
callback(transport.outBuffers)
}
function deserialize(data, callback){
var transport = new thrift.TFramedTransport(data);
var protocol = new thrift.TBinaryProtocol(transport);
var aProfile = new profile.Profile();
aProfile.read(protocol);
callback(aProfile);
}
var aProfile = new profile.Profile({exposure:2,kineticCycleTime:3});
serialize(aProfile, function(serialized){
log('serialization complete:' + serialized);
deserialize(serialized, function(deserialized){
log('deserialization complete');
log(JSON.stringify(deserialized));
});
});
答案 0 :(得分:0)
我们在node.js中有一些thrift问题(使用一些差异库)我们编写了一些示例,其中添加了一些修复,请在那里查看 - https://github.com/imysak/using-thrift