Expose length of buffered WebSocket data
Some encodings don't know how much data they need, rather they must probe the data stream until they find an end marker. Expose how much data is buffered in order to make this search efficient.
This commit is contained in:
@@ -124,6 +124,10 @@ export default class Websock {
|
|||||||
return res >>> 0;
|
return res >>> 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rQlen() {
|
||||||
|
return this._rQlen - this._rQi;
|
||||||
|
}
|
||||||
|
|
||||||
rQshiftStr(len) {
|
rQshiftStr(len) {
|
||||||
let str = "";
|
let str = "";
|
||||||
// Handle large arrays in steps to avoid long strings on the stack
|
// Handle large arrays in steps to avoid long strings on the stack
|
||||||
|
|||||||
@@ -47,6 +47,20 @@ describe('Websock', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('rQlen())', function () {
|
||||||
|
it('should return the number of buffered bytes in the receive queue', function () {
|
||||||
|
websock._receiveData(new Uint8Array([0xab, 0xcd, 0x12, 0x34,
|
||||||
|
0x88, 0xee, 0x11, 0x33]));
|
||||||
|
expect(sock.rQlen()).to.equal(8);
|
||||||
|
sock.rQshift8();
|
||||||
|
expect(sock.rQlen()).to.equal(7);
|
||||||
|
sock.rQshift16();
|
||||||
|
expect(sock.rQlen()).to.equal(5);
|
||||||
|
sock.rQshift32();
|
||||||
|
expect(sock.rQlen()).to.equal(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('rQshiftStr', function () {
|
describe('rQshiftStr', function () {
|
||||||
it('should shift the given number of bytes off of the receive queue and return a string', function () {
|
it('should shift the given number of bytes off of the receive queue and return a string', function () {
|
||||||
websock._receiveData(new Uint8Array([0xab, 0xcd, 0x12, 0x34,
|
websock._receiveData(new Uint8Array([0xab, 0xcd, 0x12, 0x34,
|
||||||
|
|||||||
Reference in New Issue
Block a user