1
0
Fork 0
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:
Robin Appelman 2017-02-05 00:53:14 +01:00
commit edf3ed5479
2 changed files with 4 additions and 8 deletions

View file

@ -57,8 +57,7 @@ export class Parser extends EventEmitter {
return this.match; return this.match;
} }
parseMessage(buffer: ArrayBuffer, type: MessageType, tick: number, length: number, match: Match): MessageParser { parseMessage(data: BitStream, type: MessageType, tick: number, length: number, match: Match): MessageParser {
const data = new BitStream(buffer);
switch (type) { switch (type) {
case MessageType.Sigon: case MessageType.Sigon:
@ -131,9 +130,7 @@ export class Parser extends EventEmitter {
} }
length = stream.readInt32(); length = stream.readInt32();
start = stream.byteIndex; buffer = stream.readBitStream(length * 8);
buffer = toBuffer(stream._view._view.slice(start, start + length));
stream.byteIndex += length;
return this.parseMessage(buffer, type, tick, length, match); return this.parseMessage(buffer, type, tick, length, match);
} }
} }

View file

@ -77,9 +77,8 @@ export class StreamParser extends Parser {
} }
console.log('got message ' + tick); console.log('got message ' + tick);
const messageBuffer = this.buffer.slice(headerSize, headerSize + length); const messageStream = stream.readBitStream(length * 8);
this.eatBuffer(headerSize + length); const message = this.parseMessage(messageStream, type, tick, length, this.match);
const message = this.parseMessage(messageBuffer, type, tick, length, this.match);
this.handleMessage(message); this.handleMessage(message);
} }
} }