Skip to content
Open
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
38 changes: 5 additions & 33 deletions lib/packets/packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
const plus = '+'.charCodeAt(0);

// TODO: handle E notation
const dot = '.'.charCodeAt(0);

Check failure on line 43 in lib/packets/packet.js

View workflow job for this annotation

GitHub Actions / lint-js

'dot' is assigned a value but never used
const exponent = 'e'.charCodeAt(0);

Check failure on line 44 in lib/packets/packet.js

View workflow job for this annotation

GitHub Actions / lint-js

'exponent' is assigned a value but never used
const exponentCapital = 'E'.charCodeAt(0);

Check failure on line 45 in lib/packets/packet.js

View workflow job for this annotation

GitHub Actions / lint-js

'exponentCapital' is assigned a value but never used

class Packet {
constructor(id, buffer, start, end) {
Expand Down Expand Up @@ -658,43 +658,15 @@
}

parseFloat(len) {
if (len === null) {
return null;
}
let result = 0;
const start = this.offset;
const end = this.offset + len;
let factor = 1;
let pastDot = false;
let charCode = 0;
this.offset += len;

if (len === 0) {
return 0; // TODO: assert? exception?
}
if (this.buffer[this.offset] === minus) {
this.offset++;
factor = -1;
}
if (this.buffer[this.offset] === plus) {
this.offset++; // just ignore
}
while (this.offset < end) {
charCode = this.buffer[this.offset];
if (charCode === dot) {
pastDot = true;
this.offset++;
} else if (charCode === exponent || charCode === exponentCapital) {
this.offset++;
const exponentValue = this.parseInt(end - this.offset);
return (result / factor) * Math.pow(10, exponentValue);
} else {
result *= 10;
result += this.buffer[this.offset] - 48;
this.offset++;
if (pastDot) {
factor = factor * 10;
}
}
}
return result / factor;

return parseFloat(this.buffer.toString('ascii', start, end));
}

parseLengthCodedIntNoBigCheck() {
Expand Down
Loading