diff --git a/frontend/app/player/MessageDistributor/PrimitiveReader.ts b/frontend/app/player/MessageDistributor/PrimitiveReader.ts index 6ee5ade4e..7dc8eb023 100644 --- a/frontend/app/player/MessageDistributor/PrimitiveReader.ts +++ b/frontend/app/player/MessageDistributor/PrimitiveReader.ts @@ -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; diff --git a/frontend/app/player/ios/Parser.ts b/frontend/app/player/ios/Parser.ts new file mode 100644 index 000000000..7791398f6 --- /dev/null +++ b/frontend/app/player/ios/Parser.ts @@ -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); + } + +} \ No newline at end of file diff --git a/frontend/app/player/ios/parser.js b/frontend/app/player/ios/parser.js deleted file mode 100644 index 83ddaec50..000000000 --- a/frontend/app/player/ios/parser.js +++ /dev/null @@ -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 - } - -} \ No newline at end of file