1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-04 00:54:14 +02:00

add encoder for parseSounds

This commit is contained in:
Robin Appelman 2017-08-16 22:33:31 +02:00
commit 9406937f08
7 changed files with 255 additions and 15 deletions

View file

@ -0,0 +1,219 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {EncodeParseSounds, ParseParseSounds} from '../../../../Parser/Packet/ParseSounds';
const data = [
18,
122,
5,
142,
169,
43,
224,
223,
63,
24,
8,
3,
126,
17,
248,
53,
0,
36,
5,
115,
140,
159,
241,
236,
67,
128,
39,
200,
47,
2,
71,
169,
15,
1,
30,
145,
0,
184,
104,
24,
103,
98,
197,
175,
0,
191,
3,
0,
252,
215,
140,
153,
209,
237,
67,
128,
89,
2,
0,
254,
25,
198,
196,
152,
246,
33,
192,
14,
228,
24,
129,
99,
206,
135,
0,
203,
3,
0,
4,
143,
35,
205,
243,
4,
73,
70,
219,
136,
245,
33,
0];
const soundData = [
199,
212,
21,
240,
239,
31,
12,
132,
1,
191,
8,
252,
26,
0,
146,
130,
57,
198,
207,
120,
246,
33,
192,
19,
228,
23,
129,
163,
212,
135,
0,
143,
72,
0,
92,
52,
140,
51,
177,
226,
87,
128,
223,
1,
0,
254,
107,
198,
204,
232,
246,
33,
192,
44,
1,
0,
255,
12,
99,
98,
76,
251,
16,
96,
7,
114,
140,
192,
49,
231,
67,
128,
229,
1,
0,
130,
199,
145,
230,
121,
130,
36,
163,
109,
196,
250,
16,
0];
const soundStream = getStream(soundData).readBitStream(726 - 25);
suite('ParseSounds', () => {
test('Parse parseSounds', () => {
soundStream.index = 0;
assertParser(ParseParseSounds, getStream(data), {
packetType: 'parseSounds',
reliable: false,
num: 9,
length: 701,
data: soundStream
}, 726);
});
test('Encode parseSounds', () => {
soundStream.index = 0;
assertEncoder(ParseParseSounds, EncodeParseSounds, {
packetType: 'parseSounds',
reliable: false,
num: 9,
length: 701,
data: soundStream
}, 726);
soundStream.index = 0;
assertEncoder(ParseParseSounds, EncodeParseSounds, {
packetType: 'parseSounds',
reliable: true,
num: 1,
length: 15,
data: soundStream.readBitStream(15)
}, 24);
});
});

View file

@ -4,8 +4,8 @@ import {EncodeVoiceData, ParseVoiceData} from '../../../../Parser/Packet/VoiceDa
const data = [5, 18, 24, 0, 123, 219, 1];
suite('VoiceInit', () => {
test('Parse voiceInit', () => {
suite('VoiceData', () => {
test('Parse voiceData', () => {
assertParser(ParseVoiceData, getStream(data), {
packetType: 'voiceData',
client: '5',
@ -15,7 +15,7 @@ suite('VoiceInit', () => {
}, 56);
});
test('Encode voiceInit', () => {
test('Encode voiceData', () => {
assertEncoder(ParseVoiceData, EncodeVoiceData, {
packetType: 'voiceData',
client: '5',

View file

@ -49,16 +49,23 @@ function objEquiv(a, b, opts) {
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
return false;
// an identical 'prototype' property.
if (a.prototype !== b.prototype) return false;
if (a.prototype !== b.prototype) {
return false;
}
//~~~I've managed to break Object.keys through screwy arguments passing.
// Converting to array solves the problem.
if (isBuffer(a)) {
if (!isBuffer(b)) {
return false;
}
if (a.length !== b.length) return false;
if (a.length !== b.length) {
return false;
}
for (i = 0; i < a.length; i++) {
if (a[i] !== b[i]) return false;
if (a[i] !== b[i]) {
return false;
}
}
return true;
}
@ -66,7 +73,9 @@ function objEquiv(a, b, opts) {
if (!isStream(b)) {
return false;
}
if (a.length !== b.length) return false;
if (a.length !== b.length) {
return false;
}
a.index = 0;
b.index = 0;
while (a.bitsLeft > 0) {