verifuint(value, 0xff);
}
- buffer[offset] = value;
+ buffer.parent[buffer.offset + offset] = value;
};
function writeUInt16(buffer, value, offset, isBigEndian, noAssert) {
}
if (isBigEndian) {
- buffer[offset] = (value & 0xff00) >>> 8;
- buffer[offset + 1] = value & 0x00ff;
+ buffer.parent[buffer.offset + offset] = (value & 0xff00) >>> 8;
+ buffer.parent[buffer.offset + offset + 1] = value & 0x00ff;
} else {
- buffer[offset + 1] = (value & 0xff00) >>> 8;
- buffer[offset] = value & 0x00ff;
+ buffer.parent[buffer.offset + offset + 1] = (value & 0xff00) >>> 8;
+ buffer.parent[buffer.offset + offset] = value & 0x00ff;
}
}
}
if (isBigEndian) {
- buffer[offset] = (value >>> 24) & 0xff;
- buffer[offset + 1] = (value >>> 16) & 0xff;
- buffer[offset + 2] = (value >>> 8) & 0xff;
- buffer[offset + 3] = value & 0xff;
+ buffer.parent[buffer.offset + offset] = (value >>> 24) & 0xff;
+ buffer.parent[buffer.offset + offset + 1] = (value >>> 16) & 0xff;
+ buffer.parent[buffer.offset + offset + 2] = (value >>> 8) & 0xff;
+ buffer.parent[buffer.offset + offset + 3] = value & 0xff;
} else {
- buffer[offset + 3] = (value >>> 24) & 0xff;
- buffer[offset + 2] = (value >>> 16) & 0xff;
- buffer[offset + 1] = (value >>> 8) & 0xff;
- buffer[offset] = value & 0xff;
+ buffer.parent[buffer.offset + offset + 3] = (value >>> 24) & 0xff;
+ buffer.parent[buffer.offset + offset + 2] = (value >>> 16) & 0xff;
+ buffer.parent[buffer.offset + offset + 1] = (value >>> 8) & 0xff;
+ buffer.parent[buffer.offset + offset] = value & 0xff;
}
}
);
t.end();
});
+
+test("hex of write{Uint,Int}{8,16,32}{LE,BE}", function(t) {
+ t.plan(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 val = (x === "Int") ? -3 : 3;
+ v1[fn](val, 0);
+ v2[fn](val, 0);
+ t.equal(
+ v1.toString("hex"),
+ v2.toString("hex")
+ );
+ });
+ });
+ });
+ t.end();
+});