From 06b51151ed8eb1c883160202b5a0de0dc2d01f8e Mon Sep 17 00:00:00 2001 From: Amazing Turtle Date: Sat, 22 Apr 2017 16:33:46 +0200 Subject: [PATCH 1/4] Create package.json --- package.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..4295c2f --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "binarywriter-node", + "description": ".NET like binarywriter in nodejs", + "version": "0.1" +} From eccc911903edf7a62fa63dded38ae86804e96ea4 Mon Sep 17 00:00:00 2001 From: Amazing Turtle Date: Sat, 22 Apr 2017 16:34:13 +0200 Subject: [PATCH 2/4] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4295c2f..d8a7160 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name": "binarywriter-node", "description": ".NET like binarywriter in nodejs", - "version": "0.1" + "version": "0.1.0" } From cc4ad759c30db71d98c63b8109e361193cdebd27 Mon Sep 17 00:00:00 2001 From: Amazing Turtle Date: Mon, 24 Apr 2017 19:39:45 +0200 Subject: [PATCH 3/4] Added LE/BE support to BinaryReader --- BinaryReader.js | 50 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/BinaryReader.js b/BinaryReader.js index 5ef2e34..7d53c63 100644 --- a/BinaryReader.js +++ b/BinaryReader.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict'; /* * Simple BinaryReader is a minimal tool to read binary stream. * Useful for binary deserialization. @@ -37,42 +37,78 @@ BinaryReader.prototype.readInt8 = function () { return value; }; -BinaryReader.prototype.readUInt16 = function () { +BinaryReader.prototype.readUInt16LE = function () { var value = this._buffer.readUInt16LE(this._offset); this._offset += 2; return value; }; -BinaryReader.prototype.readInt16 = function () { +BinaryReader.prototype.readUInt16BE = function () { + var value = this._buffer.readUInt16BE(this._offset); + this._offset += 2; + return value; +}; + +BinaryReader.prototype.readInt16LE = function () { var value = this._buffer.readInt16LE(this._offset); this._offset += 2; return value; }; -BinaryReader.prototype.readUInt32 = function () { +BinaryReader.prototype.readInt16BE = function () { + var value = this._buffer.readInt16BE(this._offset); + this._offset += 2; + return value; +}; + +BinaryReader.prototype.readUInt32LE = function () { var value = this._buffer.readUInt32LE(this._offset); this._offset += 4; return value; }; -BinaryReader.prototype.readInt32 = function () { +BinaryReader.prototype.readUInt32BE = function () { + var value = this._buffer.readUInt32BE(this._offset); + this._offset += 4; + return value; +}; + +BinaryReader.prototype.readInt32LE = function () { var value = this._buffer.readInt32LE(this._offset); this._offset += 4; return value; }; -BinaryReader.prototype.readFloat = function () { +BinaryReader.prototype.readInt32BE = function () { + var value = this._buffer.readInt32LE(this._offset); + this._offset += 4; + return value; +}; + +BinaryReader.prototype.readFloatLE = function () { var value = this._buffer.readFloatLE(this._offset); this._offset += 4; return value; }; -BinaryReader.prototype.readDouble = function () { +BinaryReader.prototype.readFloatBE = function () { + var value = this._buffer.readFloatBE(this._offset); + this._offset += 4; + return value; +}; + +BinaryReader.prototype.readDoubleLE = function () { var value = this._buffer.readDoubleLE(this._offset); this._offset += 8; return value; }; +BinaryReader.prototype.readDoubleBE = function () { + var value = this._buffer.readDoubleBE(this._offset); + this._offset += 8; + return value; +}; + BinaryReader.prototype.readBytes = function (length) { return this._buffer.slice(this._offset, this._offset + length); this._offset += length; From 414ef673c3a07bc8e303722000b04c9770213c78 Mon Sep 17 00:00:00 2001 From: Amazing Turtle Date: Mon, 24 Apr 2017 19:40:01 +0200 Subject: [PATCH 4/4] Added LE/BE support to BinaryWriter --- BinaryWriter.js | 54 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/BinaryWriter.js b/BinaryWriter.js index 83926b1..60ba712 100644 --- a/BinaryWriter.js +++ b/BinaryWriter.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict'; /* * Simple BinaryWriter is a minimal tool to write binary stream with unpredictable size. * Useful for binary serialization. @@ -40,19 +40,31 @@ BinaryWriter.prototype.writeInt8 = function (value) { this._buffer[this._length++] = value; }; -BinaryWriter.prototype.writeUInt16 = function (value) { +BinaryWriter.prototype.writeUInt16BE = function (value) { + checkAlloc(this, 2); + this._buffer[this._length++] = value >> 8; + this._buffer[this._length++] = value; +}; + +BinaryWriter.prototype.writeUInt16LE = function (value) { checkAlloc(this, 2); this._buffer[this._length++] = value; this._buffer[this._length++] = value >> 8; }; -BinaryWriter.prototype.writeInt16 = function (value) { +BinaryWriter.prototype.writeInt16BE = function (value) { + checkAlloc(this, 2); + this._buffer[this._length++] = value >> 8; + this._buffer[this._length++] = value; +}; + +BinaryWriter.prototype.writeInt16LE = function (value) { checkAlloc(this, 2); this._buffer[this._length++] = value; this._buffer[this._length++] = value >> 8; }; -BinaryWriter.prototype.writeUInt32 = function (value) { +BinaryWriter.prototype.writeUInt32BE = function (value) { checkAlloc(this, 4); this._buffer[this._length++] = value; this._buffer[this._length++] = value >> 8; @@ -60,7 +72,23 @@ BinaryWriter.prototype.writeUInt32 = function (value) { this._buffer[this._length++] = value >> 24; }; -BinaryWriter.prototype.writeInt32 = function (value) { +BinaryWriter.prototype.writeUInt32LE = function (value) { + checkAlloc(this, 4); + this._buffer[this._length++] = value >> 24; + this._buffer[this._length++] = value >> 16; + this._buffer[this._length++] = value >> 8; + this._buffer[this._length++] = value; +}; + +BinaryWriter.prototype.writeInt32BE = function (value) { + checkAlloc(this, 4); + this._buffer[this._length++] = value >> 24; + this._buffer[this._length++] = value >> 16; + this._buffer[this._length++] = value >> 8; + this._buffer[this._length++] = value; +}; + +BinaryWriter.prototype.writeInt32LE = function (value) { checkAlloc(this, 4); this._buffer[this._length++] = value; this._buffer[this._length++] = value >> 8; @@ -68,13 +96,25 @@ BinaryWriter.prototype.writeInt32 = function (value) { this._buffer[this._length++] = value >> 24; }; -BinaryWriter.prototype.writeFloat = function (value) { +BinaryWriter.prototype.writeFloatBE = function (value) { + checkAlloc(this, 4); + this._buffer.writeFloatBE(value, this._length, true); + this._length += 4; +}; + +BinaryWriter.prototype.writeFloatLE = function (value) { checkAlloc(this, 4); this._buffer.writeFloatLE(value, this._length, true); this._length += 4; }; -BinaryWriter.prototype.writeDouble = function (value) { +BinaryWriter.prototype.writeDoubleBE = function (value) { + checkAlloc(this, 8); + this._buffer.writeDoubleBE(value, this._length, true); + this._length += 8; +}; + +BinaryWriter.prototype.writeDoubleLE = function (value) { checkAlloc(this, 8); this._buffer.writeDoubleLE(value, this._length, true); this._length += 8;