mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 09:04:13 +02:00
simple parser for menu
This commit is contained in:
parent
344d76fb97
commit
70bdf0257e
4 changed files with 48 additions and 16 deletions
|
|
@ -1,14 +0,0 @@
|
|||
import {BitStream} from 'bit-buffer';
|
||||
import {MenuPacket} from '../../Data/Packet';
|
||||
|
||||
export function ParseMenu(stream: BitStream): MenuPacket {
|
||||
const type = stream.readUint16();
|
||||
const length = stream.readUint16();
|
||||
const data = stream.readBitStream(length * 8); // length is in bytes
|
||||
return {
|
||||
packetType: 'menu',
|
||||
type,
|
||||
length,
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
|
@ -47,6 +47,9 @@ function readItem(stream: BitStream, description: string, data) {
|
|||
} else if (description[0] === 'u') {
|
||||
const length = parseInt(description.substr(1), 10);
|
||||
return stream.readBits(length);
|
||||
} else if (description[0] === '$' && description.substr(description.length - 2) === '*8') {
|
||||
const variable = description.substr(1, description.length - 3);
|
||||
return stream.readBitStream(data[variable] * 8);
|
||||
} else if (description[0] === '$') {
|
||||
const variable = description.substr(1);
|
||||
return stream.readBitStream(data[variable]);
|
||||
|
|
@ -70,6 +73,9 @@ function writeItem(stream: BitStream, description: string, data, value: boolean
|
|||
} else if (description[0] === 'u') {
|
||||
const length = parseInt(description.substr(1), 10);
|
||||
return stream.writeBits(value as number, length);
|
||||
} else if (description[0] === '$' && description.substr(description.length - 2) === '*8') {
|
||||
const variable = description.substr(1, description.length - 3);
|
||||
return stream.writeBitStream(value as BitStream, data[variable] * 8);
|
||||
} else if (description[0] === '$') {
|
||||
const variable = description.substr(1);
|
||||
return stream.writeBitStream(value as BitStream, data[variable]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue