From e2d80e8e2aa116b149ac00c9aa9753211d0b4e2d Mon Sep 17 00:00:00 2001 From: scythianfuego Date: Thu, 16 Oct 2014 15:31:22 +0400 Subject: [PATCH 1/4] Update offset-buffer.js UInt8 read and write --- offset-buffer.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/offset-buffer.js b/offset-buffer.js index ebaee0e..1f4be3b 100644 --- a/offset-buffer.js +++ b/offset-buffer.js @@ -19,7 +19,12 @@ module.exports = function(ref, int24, logger) { // Basic Buffer functionality ---------------------------- - OffsetBuffer.prototype.writeInt8 = function(value) { + OffsetBuffer.prototype.writeUInt8 = function(value) { + this.buf.writeInt8(value, this.write_offset); + this.write_offset += 1; + }; + + OffsetBuffer.prototype.writeUInt8 = function(value) { this.buf.writeInt8(value, this.write_offset); this.write_offset += 1; }; @@ -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 +}; From c6f57788fa415c405cd460bacad61d79b0e4908b Mon Sep 17 00:00:00 2001 From: scythianfuego Date: Fri, 17 Oct 2014 11:14:32 +0400 Subject: [PATCH 2/4] Unsigned Int8 read/write (corrected typos) corrected typos --- offset-buffer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/offset-buffer.js b/offset-buffer.js index 1f4be3b..a93ec3f 100644 --- a/offset-buffer.js +++ b/offset-buffer.js @@ -19,13 +19,13 @@ module.exports = function(ref, int24, logger) { // Basic Buffer functionality ---------------------------- - OffsetBuffer.prototype.writeUInt8 = function(value) { + OffsetBuffer.prototype.writeInt8 = function(value) { this.buf.writeInt8(value, this.write_offset); this.write_offset += 1; }; OffsetBuffer.prototype.writeUInt8 = function(value) { - this.buf.writeInt8(value, this.write_offset); + this.buf.writeUInt8(value, this.write_offset); this.write_offset += 1; }; @@ -79,7 +79,7 @@ module.exports = function(ref, int24, logger) { 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); From 2113e3942becb6f0ddb29c6dfa02b2ead89c6e2f Mon Sep 17 00:00:00 2001 From: scythianfuego Date: Wed, 17 Dec 2014 15:01:26 +0300 Subject: [PATCH 3/4] Test readUInt8/writeUInt8 --- test/offset-buffer-test.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) 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(); }); - - - - - - - - - - From db39ff296221e6c2c4a86a6ed523287088c18fc5 Mon Sep 17 00:00:00 2001 From: scythianfuego Date: Wed, 17 Dec 2014 15:02:13 +0300 Subject: [PATCH 4/4] Corrected a typo --- offset-buffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/offset-buffer.js b/offset-buffer.js index a93ec3f..abad39e 100644 --- a/offset-buffer.js +++ b/offset-buffer.js @@ -75,7 +75,7 @@ module.exports = function(ref, int24, logger) { return result; }; - OffsetBuffer.prototype.readUInt8() = function() { + OffsetBuffer.prototype.readUInt8 = function() { var result = this.buf.readUInt8(this.read_offset); this.read_offset += 1; return result;