代码拉取完成,页面将自动刷新
// import { writeLog } from "./Log.js";
import { writeErrLog } from "./Log.js";
/**
* 对buffer进行切割
*/
export default class UnitCache {
constructor() {
// this.spliceUnits = [];
this.cacheBuf = [];
}
put(buf) {
/**
* 拼接两个unit8Array
*/
const target = new Uint8Array(buf);
if (this.cacheBuf.byteLength) {
const source = this.cacheBuf;
this.cacheBuf = new Uint8Array(newUnit8.byteLength + this.cacheBuf.byteLength);
this.cacheBuf.set(source, 0);
this.cacheBuf.set(target, source.byteLength);
} else {
this.cacheBuf = target;
}
// 00 00 00 01 或者 00 00 01 分割码
/**
* 1.找数值为00的
* 2.判断相邻的两个或者三个字节是否满足条件
*/
let index = 0;
let subCodeStartIndexs = [];
while (index < this.cacheBuf.byteLength) {
if (this.cacheBuf[index] === 0 && this.cacheBuf[index + 1] === 0) {
if (this.cacheBuf[index + 2] === 1) {
// writeLog("00 00 01:" + index);
subCodeStartIndexs.push({
index,
len: 3
});
index += 3;
} else if (this.cacheBuf[index + 2] === 0 && this.cacheBuf[index + 3] === 1) {
// writeLog("00 00 00 01:" + index);
subCodeStartIndexs.push({
index,
len: 4
});
index += 4;
} else {
index++;
}
} else {
index++;
}
}
let spliceUnits = [];
const indexsLength = subCodeStartIndexs.length;
for (let index = 0; index < indexsLength; index++) {
const sub = subCodeStartIndexs[index];
const nextSub = subCodeStartIndexs[index + 1];
if (nextSub) {
const slice = this.cacheBuf.subarray(sub.index + sub.len, nextSub.index);
spliceUnits.push(slice);
}
}
this.cacheBuf = this.cacheBuf.subarray(subCodeStartIndexs[indexsLength - 1]);
return spliceUnits;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。