fix(frontend): IOS Parser
This commit is contained in:
parent
a5af6eb0dd
commit
0b812683d7
3 changed files with 33 additions and 31 deletions
|
|
@ -1,6 +1,10 @@
|
|||
export default class PrimitiveReader {
|
||||
protected p = 0
|
||||
constructor(protected readonly buf: Uint8Array) {}
|
||||
|
||||
hasNext() {
|
||||
return this.buf.length < this.buf.p
|
||||
}
|
||||
|
||||
readUint() {
|
||||
var r = 0, s = 1, b;
|
||||
|
|
|
|||
29
frontend/app/player/ios/Parser.ts
Normal file
29
frontend/app/player/ios/Parser.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import readMessage from '../MessageDistributor/messages';
|
||||
import PrimitiveReader from '../MessageDistributor/PrimitiveReader';
|
||||
|
||||
|
||||
export default class Parser {
|
||||
private reader: PrimitiveReader
|
||||
private error = null
|
||||
constructor(byteArray) {
|
||||
this.reader = new PrimitiveReader(byteArray)
|
||||
}
|
||||
|
||||
parseEach(cb) {
|
||||
while (this.hasNext()) {
|
||||
const msg = this.parseNext();
|
||||
if (msg !== null) {
|
||||
cb(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hasNext() {
|
||||
return !this.error && this.reader.hasNext();
|
||||
}
|
||||
|
||||
parseNext() {
|
||||
return readMessage(this.reader);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
import readMessage from '../MessageDistributor/messages';
|
||||
|
||||
|
||||
export default class Parser {
|
||||
_p = 0
|
||||
_data
|
||||
_error = null
|
||||
constructor(byteArray) {
|
||||
this._data = byteArray;
|
||||
}
|
||||
|
||||
parseEach(cb) {
|
||||
while (this.hasNext()) {
|
||||
const msg = this.parseNext();
|
||||
if (msg !== null) {
|
||||
cb(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hasNext() {
|
||||
return !this._error && this._data.length > this._p;
|
||||
}
|
||||
|
||||
parseNext() {
|
||||
let msg;
|
||||
[ msg, this._p ] = readMessage(this._data, this._p);
|
||||
return msg
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue