【问题标题】:Node Thrift DeserializationNode Thrift 反序列化
【发布时间】:2013-05-04 04:10:10
【问题描述】:

我正在尝试做一个简单的节俭序列化/反序列化,但是如果我的反序列化失败并显示以下消息:

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

【问题讨论】:

    标签: javascript node.js thrift thrift-protocol


    【解决方案1】:

    我们在 node.js 中遇到了一些节俭问题(使用一些 diff 库)我们编写了添加一些修复的示例,请在那里查看 - https://github.com/imysak/using-thrift

    【讨论】:

      猜你喜欢
      • 2012-11-14
      • 2019-08-11
      • 1970-01-01
      • 2016-03-24
      • 2014-08-10
      • 2016-09-16
      • 2015-06-07
      • 1970-01-01
      • 2018-03-31
      相关资源
      最近更新 更多