diff --git a/lib/jpickle.js b/lib/jpickle.js index cae9f04..84b9169 100644 --- a/lib/jpickle.js +++ b/lib/jpickle.js @@ -1,3 +1,4 @@ + var emulated = { 'datetime.datetime': function(args) { var tmp = new Buffer(args[0], 'binary') @@ -94,7 +95,7 @@ Parser.prototype.load = function(pickle) { var opindex = i , opcode = pickle[i++]; //console.log('opcode ' + opindex + ' ' + opcode); - switch (opcode) { + switch (String.fromCharCode(opcode)) { // protocol 2 case PROTO: var proto = buffer.readUInt8(i++); @@ -124,9 +125,12 @@ Parser.prototype.load = function(pickle) { break; case LONG1: var length = buffer.readUInt8(i++); - // FIXME: actually decode LONG1 + var val = 0n; + for (var x = 0; x < length; x++) { + val |= BigInt(buffer[x+i]) << (BigInt(x) * 8n); + } i += length; - this.stack.push(0); + this.stack.push(length == 2 ? ((val & 0x8000n) ? val | 0xFFFF0000n : val) : val); break; case LONG4: var length = buffer.readUInt32LE(i); @@ -338,7 +342,7 @@ Parser.prototype.load = function(pickle) { this.stack.push(null); break; default: - throw "Unhandled opcode '" + opcode + "'"; + throw "Unhandled opcode '" + opcode + "' (" + String.fromCharCode(opcode) + ")" + " at " + i; } } };