Skip to content

Commit

Permalink
Update structure.js
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Aug 8, 2022
1 parent add13b2 commit 2b42965
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/packet/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

class STRUCTURE {
constructor(packet) {
this.packet = (packet == undefined) ? Buffer.from('') : packet;
packet = (packet == undefined) ? Buffer.from('') : packet;
this.packet = packet;
this.totalLength = packet.length;
this.offset = 0;
};

Expand All @@ -21,7 +23,7 @@ class STRUCTURE {
readSGString() {
const dataLength = this.readUInt16();
const data = this.packet.slice(this.offset, this.offset + dataLength);
this.offset = this.offset + 1 + dataLength;
this.offset = (this.offset + 1 + dataLength);
return data;
};

Expand All @@ -35,12 +37,11 @@ class STRUCTURE {
let data = '';

if (count == false) {
const totalLength = this.packet.length;
data = this.packet.slice(this.offset);
this.offset = totalLength;
this.offset = this.totalLength;
} else {
data = this.packet.slice(this.offset, this.offset + count);
this.offset = this.offset + count;
this.offset = (this.offset + count);
};
return data;
};
Expand All @@ -54,7 +55,7 @@ class STRUCTURE {

readUInt8() {
const data = this.packet.readUInt8BE(this.offset);
this.offset = this.offset + 1;
this.offset = (this.offset + 1);
return data;
};

Expand All @@ -67,7 +68,7 @@ class STRUCTURE {

readUInt16() {
const data = this.packet.readUInt16BE(this.offset);
this.offset = this.offset + 2;
this.offset = (this.offset + 2);
return data;
};

Expand All @@ -80,7 +81,7 @@ class STRUCTURE {

readUInt32() {
const data = this.packet.readUInt32BE(this.offset);
this.offset = this.offset + 4;
this.offset = (this.offset + 4);
return data;
};

Expand All @@ -93,7 +94,7 @@ class STRUCTURE {

readInt32() {
const data = this.packet.readInt32BE(this.offset);
this.offset = this.offset + 4;
this.offset = (this.offset + 4);
return data;
};

Expand All @@ -107,11 +108,10 @@ class STRUCTURE {
};

add(data) {
const packet = Buffer.concat([
this.packet = Buffer.concat([
this.packet,
data
]);
this.packet = packet;
};
};
module.exports = STRUCTURE;

0 comments on commit 2b42965

Please sign in to comment.