refactor: name
This commit is contained in:
parent
3df5266ba3
commit
500ada03ff
|
@ -1,14 +1,14 @@
|
|||
import gather from '@/lib/gather.js';
|
||||
|
||||
const Gathered = gather(import.meta.glob('./*.js', {eager: true, import: 'default'}));
|
||||
const Packets = gather(import.meta.glob('./*.js', {eager: true, import: 'default'}));
|
||||
|
||||
const typeToId = new Map(Object.entries(Gathered).map(([type], id) => [type, id]));
|
||||
const idToType = new Map(Object.entries(Gathered).map(([type], id) => [id, type]));
|
||||
const typeToId = new Map(Object.entries(Packets).map(([type], id) => [type, id]));
|
||||
const idToType = new Map(Object.entries(Packets).map(([type], id) => [id, type]));
|
||||
|
||||
export function decode(packed) {
|
||||
const view = ArrayBuffer.isView(packed) ? packed : new DataView(packed);
|
||||
const type = idToType.get(view.getUint16(0, true));
|
||||
const Packet = Gathered[type];
|
||||
const Packet = Packets[type];
|
||||
return {
|
||||
type,
|
||||
payload: Packet.decode(view),
|
||||
|
@ -16,7 +16,7 @@ export function decode(packed) {
|
|||
}
|
||||
|
||||
export function encode(packet) {
|
||||
const encoded = Gathered[packet.type].encode(packet.payload);
|
||||
const encoded = Packets[packet.type].encode(packet.payload);
|
||||
encoded.setUint16(0, typeToId.get(packet.type), true);
|
||||
return encoded;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user