msgpacklib

a msgpack implementation

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.org/scripts/450632/1088933/msgpacklib.js

作者
Nuro#9818
版本
0.0.1.20220902185359
创建于
2022-09-02
更新于
2022-09-02
许可证
暂无
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