mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
use readBitStream in parser so we can reuse the existing buffers
This commit is contained in:
parent
3c9dbe9936
commit
edf3ed5479
2 changed files with 4 additions and 8 deletions
|
|
@ -57,8 +57,7 @@ export class Parser extends EventEmitter {
|
|||
return this.match;
|
||||
}
|
||||
|
||||
parseMessage(buffer: ArrayBuffer, type: MessageType, tick: number, length: number, match: Match): MessageParser {
|
||||
const data = new BitStream(buffer);
|
||||
parseMessage(data: BitStream, type: MessageType, tick: number, length: number, match: Match): MessageParser {
|
||||
|
||||
switch (type) {
|
||||
case MessageType.Sigon:
|
||||
|
|
@ -131,9 +130,7 @@ export class Parser extends EventEmitter {
|
|||
}
|
||||
|
||||
length = stream.readInt32();
|
||||
start = stream.byteIndex;
|
||||
buffer = toBuffer(stream._view._view.slice(start, start + length));
|
||||
stream.byteIndex += length;
|
||||
buffer = stream.readBitStream(length * 8);
|
||||
return this.parseMessage(buffer, type, tick, length, match);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,9 +77,8 @@ export class StreamParser extends Parser {
|
|||
}
|
||||
|
||||
console.log('got message ' + tick);
|
||||
const messageBuffer = this.buffer.slice(headerSize, headerSize + length);
|
||||
this.eatBuffer(headerSize + length);
|
||||
const message = this.parseMessage(messageBuffer, type, tick, length, this.match);
|
||||
const messageStream = stream.readBitStream(length * 8);
|
||||
const message = this.parseMessage(messageStream, type, tick, length, this.match);
|
||||
this.handleMessage(message);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue