Rewrite gateway message decoding
This commit is contained in:
parent
99d40a5a06
commit
4cb6c2639f
@ -16,20 +16,24 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
|
|||||||
// TODO: compression
|
// TODO: compression
|
||||||
var data: Payload;
|
var data: Payload;
|
||||||
|
|
||||||
if (this.encoding === "etf" && buffer instanceof Buffer)
|
if (
|
||||||
data = erlpack.unpack(buffer);
|
(buffer instanceof Buffer && buffer[0] === 123) ||
|
||||||
else if (this.encoding === "json" && buffer instanceof Buffer && buffer[0] !== 123) { // bad check for "{"
|
(typeof buffer === "string")
|
||||||
|
) {
|
||||||
|
data = bigIntJson.parse(buffer.toString());
|
||||||
|
}
|
||||||
|
else if (this.encoding === "json" && buffer instanceof Buffer) {
|
||||||
if (this.inflate) {
|
if (this.inflate) {
|
||||||
try {
|
try { buffer = this.inflate.process(buffer) as any; }
|
||||||
buffer = this.inflate.process(buffer) as any;
|
catch { buffer = buffer.toString() as any; }
|
||||||
} catch {
|
|
||||||
buffer = buffer.toString() as any;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
data = bigIntJson.parse(buffer as string);
|
data = bigIntJson.parse(buffer as string);
|
||||||
} else if (typeof buffer == "string" || (buffer instanceof Buffer && buffer[0] == 123)) {
|
}
|
||||||
data = bigIntJson.parse(buffer as string);
|
else if (this.encoding === "etf" && buffer instanceof Buffer) {
|
||||||
} else return;
|
try { data = erlpack.unpack(buffer); }
|
||||||
|
catch { return this.close(CLOSECODES.Decode_error); }
|
||||||
|
}
|
||||||
|
else return this.close(CLOSECODES.Decode_error);
|
||||||
|
|
||||||
check.call(this, PayloadSchema, data);
|
check.call(this, PayloadSchema, data);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user