5 Star 35 Fork 13

nygula / Node-Media-Server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
node_core_bitop.js 968 Bytes
一键复制 编辑 原始数据 按行查看 历史
Chen Mingliang 提交于 2020-07-16 19:50 . Add eslint support
class Bitop {
constructor(buffer) {
this.buffer = buffer;
this.buflen = buffer.length;
this.bufpos = 0;
this.bufoff = 0;
this.iserro = false;
}
read(n) {
let v = 0;
let d = 0;
while (n) {
if (n < 0 || this.bufpos >= this.buflen) {
this.iserro = true;
return 0;
}
this.iserro = false;
d = this.bufoff + n > 8 ? 8 - this.bufoff : n;
v <<= d;
v += (this.buffer[this.bufpos] >> (8 - this.bufoff - d)) & (0xff >> (8 - d))
this.bufoff += d;
n -= d;
if (this.bufoff == 8) {
this.bufpos++;
this.bufoff = 0;
}
}
return v;
}
look(n) {
let p = this.bufpos;
let o = this.bufoff;
let v = this.read(n);
this.bufpos = p;
this.bufoff = o;
return v;
}
read_golomb() {
let n;
for (n = 0; this.read(1) == 0 && !this.iserro; n++);
return (1 << n) + this.read(n) - 1;
}
}
module.exports = Bitop;
1
https://gitee.com/nygula/Node-Media-Server.git
git@gitee.com:nygula/Node-Media-Server.git
nygula
Node-Media-Server
Node-Media-Server
master

搜索帮助