msgpacklib

a msgpack implementation

Dette scriptet burde ikke installeres direkte. Det er et bibliotek for andre script å inkludere med det nye metadirektivet // @require https://update.greasyfork.org/scripts/450632/1088933/msgpacklib.js

Forfatter
Nuro#9818
Versjon
0.0.1.20220902185359
Lagd
02.09.2022
Oppdatert
02.09.2022
Lisens
I/T
const Writer = msgpacklib.writer;
const Reader = msgpacklib.reader;

receive packets:

onmessage = function (e) {
    let data = e.data;
    let packet = new Reader(data);
    let [packetID, info] = packet.readData();
}

send packets:

 function send(packetID, ...args) {
    let binData = new Writer(1, args).setString(packetID).setInt(144 + args.length, !0);
    args && args.forEach(e => {
        switch (typeof e) {
            case 'number':
                Number.isSafeInteger(e) ? binData.setInt(e) : binData.setFloat(e);
                break;
            case 'string':
                binData.setString(e);
        }
    });
    let packet = binData.arraybuffer;
    socket.send(packet);
    return packet;
}

made for moomoo.io so idk if u wanna use it in other stuff