msgpacklib

a msgpack implementation

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

  1. const msgpacklib = {
  2. reader: class {
  3. constructor(t, e = 0) {
  4. return this.buffer = t, this.dv = new DataView(this.buffer.buffer || this.buffer), this.offset = e, this
  5. }
  6. readString(t) {
  7. let e = (t || this.dv.getUint8(this.offset++)) - 160,
  8. s = "";
  9. for (let t = 0; t < e; t++) s += String.fromCharCode(this.dv.getUint8(this.offset++));
  10. return s
  11. }
  12. getArrayLegth() {
  13. return this.dv.getUint8(this.offset++) - 144
  14. }
  15. readData() {
  16. let t = this.dv.getUint8(this.offset++);
  17. if (t < 128) return t;
  18. if (t > 223) return this.dv.getInt8(this.offset - 1);
  19. if (192 === t) return null;
  20. if (195 === t) return !0;
  21. if (194 === t) return !1;
  22. if (t > 202 && t < 2010) switch (t) {
  23. case 203:
  24. return this.offset += 8, this.dv.getFloat64(this.offset - 8);
  25. case 204:
  26. return this.dv.getUint8(this.offset++);
  27. case 205:
  28. return this.offset += 2, this.dv.getUint16(this.offset - 2);
  29. case 206:
  30. return this.offset += 4, this.dv.getUint32(this.offset - 4);
  31. case 208:
  32. return this.dv.getInt8(this.offset++);
  33. case 209:
  34. return this.dv.getInt16((this.offset += 2) - 2)
  35. } else {
  36. if (t > 159 && t < 192) return this.readString(t);
  37. if (t > 143 && t < 160 || 220 === t) {
  38. let e = 220 === t ? this.dv.getUint16((this.offset += 2) - 2) : t - 144,
  39. s = [];
  40. for (let t = 0; t < e; t++) s.push(this.readData());
  41. return s
  42. }
  43. if (t > 127 && t < 144) {
  44. let e = t - 128,
  45. s = {};
  46. for (let t = 0; t < e; t++) s[this.readString()] = this.readData();
  47. return s
  48. }
  49. }
  50. }
  51. },
  52. writer: class {
  53. constructor(t = 1, e) {
  54. return 0 === t && (t = 1), this.offset = 0, this.buffer = new Uint8Array(t), this.dv = new DataView(this.buffer.buffer), this.setInt(146, !0), this
  55. }
  56. inflate(t = 1) {
  57. if (this.offset + t < this.buffer.length) return;
  58. let e = new Uint8Array(2 * this.buffer.length);
  59. this.buffer.forEach((t, s) => e[s] = t), this.buffer = e, this.dv = new DataView(this.buffer.buffer), t + this.offset >= this.buffer.length && this.inflate(t)
  60. }
  61. setFloat(t) {
  62. return this.inflate(8), this.dv.setFloat64(this.offset, t), this.offset += 8, this
  63. }
  64. setInt(t, e) {
  65. return !e && t > 127 && (this.inflate(), this.dv.setUint8(this.offset++, 204)), this.inflate(), this.dv.setUint8(this.offset++, t), this
  66. }
  67. setString(t) {
  68. return t.length >= 32 ? (this.setInt(217, !0), this.setInt(t.length, !0)) : this.setInt(160 + t.length, !0), t.split("").forEach(t => this.setInt(t.charCodeAt(), !0)), this
  69. }
  70. get arraybuffer() {
  71. return this.buffer.slice(0, this.offset)
  72. }
  73. }
  74. };
  75. window.msgpacklib = msgpacklib;

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址