Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion offset-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ module.exports = function(ref, int24, logger) {
this.buf.writeInt8(value, this.write_offset);
this.write_offset += 1;
};

OffsetBuffer.prototype.writeUInt8 = function(value) {
this.buf.writeUInt8(value, this.write_offset);
this.write_offset += 1;
};

OffsetBuffer.prototype.writeInt16BE = function(value) {
this.buf.writeInt16BE(value, this.write_offset);
Expand Down Expand Up @@ -69,6 +74,12 @@ module.exports = function(ref, int24, logger) {
this.read_offset += 1;
return result;
};

OffsetBuffer.prototype.readUInt8 = function() {
var result = this.buf.readUInt8(this.read_offset);
this.read_offset += 1;
return result;
};

OffsetBuffer.prototype.readInt16BE = function() {
var result = this.buf.readInt16BE(this.read_offset);
Expand Down Expand Up @@ -251,4 +262,4 @@ module.exports = function(ref, int24, logger) {
};

return OffsetBuffer;
};
};
26 changes: 16 additions & 10 deletions test/offset-buffer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ test('writeInt8', function(t) {
t.end();
});

test('writeUInt8', function(t) {
var b = new OffsetBuffer(1);
b.writeUInt8(0xfe);
t.equal(b.buf[0], 0xfe, 'writeUInt8: Written data matches');
t.equal(b.write_offset, 1, 'writeUInt8: write offset correct');
t.end();
});

test('writeInt16BE', function(t) {
var b = new OffsetBuffer(2);
b.writeInt16BE(0x04);
Expand Down Expand Up @@ -176,6 +184,14 @@ test('readInt8', function(t) {
t.end();
});

test('readUInt8', function(t) {
var b = new OffsetBuffer([0xfe]);
t.equal(b.readUInt8(), 0xfe, 'readInt8: Read data matches');
t.equal(b.read_offset, 1, 'readInt8: read offset correct');
t.end();
});


test('readInt16BE', function(t) {
var b = new OffsetBuffer([0x04, 0x05]);
t.equal(b.readInt16BE(), 1029, 'readInt16BE: Read data matches');
Expand Down Expand Up @@ -342,13 +358,3 @@ test('copyTo', function(t) {
t.equal(from.read_offset, 5, 'copyTo: read offset at the end of the buffer');
t.end();
});