-
Notifications
You must be signed in to change notification settings - Fork 11
/
Reliable.ts
44 lines (35 loc) · 1.23 KB
/
Reliable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { SendOption } from "@skeldjs/constant";
import { HazelReader, HazelWriter } from "@skeldjs/util";
import { BaseRootMessage } from "../root/BaseRootMessage";
import { PacketDecoder } from "../../PacketDecoder";
import { MessageDirection } from "../../PacketDecoder";
import { NormalPacket } from "./Normal";
export class ReliablePacket extends NormalPacket {
static messageTag = SendOption.Reliable as const;
messageTag = SendOption.Reliable as const;
readonly nonce: number;
constructor(nonce: number, children: BaseRootMessage[]) {
super(children);
this.nonce = nonce;
}
static Deserialize(
reader: HazelReader,
direction: MessageDirection,
decoder: PacketDecoder
) {
const nonce = reader.uint16(true);
const normal = super.Deserialize(reader, direction, decoder);
return new ReliablePacket(nonce, normal.children);
}
Serialize(
writer: HazelWriter,
direction: MessageDirection,
decoder: PacketDecoder
) {
writer.uint16(this.nonce, true);
super.Serialize(writer, direction, decoder);
}
clone() {
return new ReliablePacket(this.nonce, this.children.map(child => child.clone()));
}
}