Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/jpickle.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

var emulated = {
'datetime.datetime': function(args) {
var tmp = new Buffer(args[0], 'binary')
Expand Down Expand Up @@ -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++);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
};
Expand Down