diff --git a/offset-buffer.js b/offset-buffer.js index ebaee0e..abad39e 100644 --- a/offset-buffer.js +++ b/offset-buffer.js @@ -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); @@ -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); @@ -251,4 +262,4 @@ module.exports = function(ref, int24, logger) { }; return OffsetBuffer; -}; \ No newline at end of file +}; diff --git a/test/offset-buffer-test.js b/test/offset-buffer-test.js index 689d79c..51156a9 100644 --- a/test/offset-buffer-test.js +++ b/test/offset-buffer-test.js @@ -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); @@ -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'); @@ -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(); }); - - - - - - - - - -