return new Buffer(this, end - start, +start);
};
+SlowBuffer.prototype.copy = function(target, targetstart, sourcestart, sourceend) {
+ var temp = [];
+ for (var i=sourcestart; i<sourceend; i++) {
+ assert.ok(typeof this[i] !== 'undefined', "copying undefined buffer bytes!");
+ temp.push(this[i]);
+ }
+
+ for (var i=targetstart; i<targetstart+temp.length; i++) {
+ target[i] = temp[i-targetstart];
+ }
+};
function coerce(length) {
// Coerce length to a number (possibly NaN), round up
'Trying to read beyond buffer length');
}
- return buffer[offset];
+ return buffer.parent[buffer.offset + offset];
};
function readUInt16(buffer, offset, isBigEndian, noAssert) {
}
if (isBigEndian) {
- val = buffer[offset] << 8;
- val |= buffer[offset + 1];
+ val = buffer.parent[buffer.offset + offset] << 8;
+ val |= buffer.parent[buffer.offset + offset + 1];
} else {
- val = buffer[offset];
- val |= buffer[offset + 1] << 8;
+ val = buffer.parent[buffer.offset + offset];
+ val |= buffer.parent[buffer.offset + offset + 1] << 8;
}
return val;
}
if (isBigEndian) {
- val = buffer[offset + 1] << 16;
- val |= buffer[offset + 2] << 8;
- val |= buffer[offset + 3];
- val = val + (buffer[offset] << 24 >>> 0);
+ val = buffer.parent[buffer.offset + offset + 1] << 16;
+ val |= buffer.parent[buffer.offset + offset + 2] << 8;
+ val |= buffer.parent[buffer.offset + offset + 3];
+ val = val + (buffer.parent[buffer.offset + offset] << 24 >>> 0);
} else {
- val = buffer[offset + 2] << 16;
- val |= buffer[offset + 1] << 8;
- val |= buffer[offset];
- val = val + (buffer[offset + 3] << 24 >>> 0);
+ val = buffer.parent[buffer.offset + offset + 2] << 16;
+ val |= buffer.parent[buffer.offset + offset + 1] << 8;
+ val |= buffer.parent[buffer.offset + offset];
+ val = val + (buffer.parent[buffer.offset + offset + 3] << 24 >>> 0);
}
return val;
'Trying to read beyond buffer length');
}
- neg = buffer[offset] & 0x80;
+ neg = buffer.parent[buffer.offset + offset] & 0x80;
if (!neg) {
- return (buffer[offset]);
+ return (buffer.parent[buffer.offset + offset]);
}
- return ((0xff - buffer[offset] + 1) * -1);
+ return ((0xff - buffer.parent[buffer.offset + offset] + 1) * -1);
};
function readInt16(buffer, offset, isBigEndian, noAssert) {
});
test("hex of write{Uint,Int}{8,16,32}{LE,BE}", function(t) {
- t.plan(2*2*2+2);
+ t.plan(2*(2*2*2+2));
["UInt","Int"].forEach(function(x){
[8,16,32].forEach(function(y){
var endianesses = (y === 8) ? [""] : ["LE","BE"];
endianesses.forEach(function(z){
var v1 = new buffer.Buffer(y / 8);
var v2 = new Buffer(y / 8);
- var fn = "write" + x + y + z;
+ var writefn = "write" + x + y + z;
var val = (x === "Int") ? -3 : 3;
- v1[fn](val, 0);
- v2[fn](val, 0);
+ v1[writefn](val, 0);
+ v2[writefn](val, 0);
t.equal(
v1.toString("hex"),
v2.toString("hex")
);
+ var readfn = "read" + x + y + z;
+ t.equal(
+ v1[readfn](0),
+ v2[readfn](0)
+ );
});
});
});