22 lines
504 B
JavaScript
22 lines
504 B
JavaScript
let eventId = 0;
|
|
const packetToIdMap = new Map();
|
|
const idToPacketMap = new Map();
|
|
export function allPackets() {
|
|
return Array.from(idToPacketMap.values());
|
|
}
|
|
export function idFromPacket(Packet) {
|
|
return packetToIdMap.get(Packet);
|
|
}
|
|
export function packetFromId(id) {
|
|
return idToPacketMap.get(id);
|
|
}
|
|
export function registerPacket(Packet) {
|
|
if (packetToIdMap.has(Packet)) {
|
|
return;
|
|
}
|
|
const id = eventId++;
|
|
packetToIdMap.set(Packet, id);
|
|
idToPacketMap.set(id, Packet);
|
|
return id;
|
|
}
|