2013-04-26 70 views
0

我試圖做一個簡單的節儉序列化/反序列化反序列化我如果有以下消息失敗:節點節儉反序列化

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

回答