Extract rQshift to common function

This commit is contained in:
Juanjo Diaz 2018-12-08 17:32:00 +02:00
parent 8a189a6291
commit 879e33ab64
1 changed files with 12 additions and 10 deletions

View File

@ -75,22 +75,24 @@ export default class Websock {
}
rQshift8() {
return this._rQ[this._rQi++];
return this._rQshift(1);
}
// TODO(directxman12): test performance with these vs a DataView
rQshift16() {
return (this._rQ[this._rQi++] << 8) +
this._rQ[this._rQi++];
return this._rQshift(2);
}
rQshift32() {
return (this._rQ[this._rQi++] << 24) +
(this._rQ[this._rQi++] << 16) +
(this._rQ[this._rQi++] << 8) +
this._rQ[this._rQi++];
return this._rQshift(4);
}
// TODO(directxman12): test performance with these vs a DataView
_rQshift(bytes) {
let res = 0;
for (let byte = bytes - 1; byte >= 0; byte--) {
res += this._rQ[this._rQi++] << (byte * 8);
}
return res;
}
rQshiftStr(len) {