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
50 changes: 43 additions & 7 deletions BinaryReader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
'use strict';
/*
* Simple BinaryReader is a minimal tool to read binary stream.
* Useful for binary deserialization.
Expand Down Expand Up @@ -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;
Expand Down
54 changes: 47 additions & 7 deletions BinaryWriter.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -40,41 +40,81 @@ 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;
this._buffer[this._length++] = value >> 16;
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;
this._buffer[this._length++] = value >> 16;
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;
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "binarywriter-node",
"description": ".NET like binarywriter in nodejs",
"version": "0.1.0"
}