193 lines
4.6 KiB
JavaScript
193 lines
4.6 KiB
JavaScript
// Metro module 1312 (f1313).
|
|
import * as _classCallCheck from "./_classCallCheck";
|
|
import * as __createClass from "./_createClass";
|
|
import { varint64read, varint32read } from "./Module1313";
|
|
import { WireType } from "./is";
|
|
import { PbLong, PbULong } from "./SharedPbLong";
|
|
let c1080_5;
|
|
let BinaryReader;
|
|
let env1080 = {};
|
|
const c1080_4 = {
|
|
readUnknownField: true,
|
|
readerFactory: (a0) => new c1080_5(a0)
|
|
};
|
|
export function binaryReadOptions(a0) {
|
|
return a0 ? {
|
|
...c1080_4,
|
|
...a0
|
|
} : c1080_4;
|
|
}
|
|
BinaryReader = function BinaryReader(a0, a1) {
|
|
let textDecoder = a1;
|
|
_classCallCheck(this, BinaryReader);
|
|
this.varint64 = varint64read;
|
|
this.uint32 = varint32read;
|
|
this.buf = a0;
|
|
this.len = a0.length;
|
|
this.pos = 0;
|
|
this.view = new DataView(a0.buffer, a0.byteOffset, a0.byteLength);
|
|
if (a1 == null) {
|
|
textDecoder = new TextDecoder("utf-8", {
|
|
fatal: true,
|
|
ignoreBOM: true
|
|
});
|
|
}
|
|
this.textDecoder = textDecoder;
|
|
};
|
|
c1080_5 = __createClass(BinaryReader, [{
|
|
key: "tag",
|
|
value: function tag() {
|
|
const r9 = this.uint32();
|
|
const r2 = r9 >>> 3;
|
|
const r11 = 7 & r9;
|
|
if (!(r2 <= 0) && !(r11 < 0) && !(5 < r11)) {
|
|
return [r2, r11];
|
|
}
|
|
throw new Error("illegal tag: field no " + r2 + " wire type " + r11);
|
|
}
|
|
}, {
|
|
key: "skip",
|
|
value: function skip(a0) {
|
|
let r72, buf2, pos;
|
|
L14: {
|
|
pos = this.pos;
|
|
if (WireType.Varint === a0) {
|
|
const buf = this.buf;
|
|
const r66 = +this.pos;
|
|
this.pos = r66 + 1;
|
|
if (128 & buf[r66]) {
|
|
do {
|
|
buf2 = this.buf;
|
|
r72 = +this.pos;
|
|
this.pos = r72 + 1;
|
|
} while (128 & buf2[r72]);
|
|
}
|
|
} else {
|
|
if (WireType.Bit64 === a0) {
|
|
this.pos = this.pos + 4;
|
|
} else if (WireType.Bit32 !== a0) {
|
|
if (WireType.LengthDelimited === a0) {
|
|
this.pos = this.pos + this.uint32();
|
|
break L14;
|
|
}
|
|
if (WireType.StartGroup !== a0) {
|
|
throw new Error("cant skip wire type " + a0);
|
|
}
|
|
let r40 = this.tag()[1];
|
|
if (r40 === WireType.EndGroup) {
|
|
break L14;
|
|
}
|
|
while (true) {
|
|
this.skip(r40);
|
|
r40 = this.tag()[1];
|
|
if (r40 === WireType.EndGroup) {
|
|
break L14;
|
|
}
|
|
}
|
|
}
|
|
this.pos = this.pos + 4;
|
|
}
|
|
}
|
|
this.assertBounds();
|
|
return this.buf.subarray(pos, this.pos);
|
|
}
|
|
}, {
|
|
key: "assertBounds",
|
|
value: function assertBounds() {
|
|
if (this.pos > this.len) {
|
|
throw new RangeError("premature EOF");
|
|
}
|
|
}
|
|
}, {
|
|
key: "int32",
|
|
value: function int32() {
|
|
return this.uint32() | 0;
|
|
}
|
|
}, {
|
|
key: "sint32",
|
|
value: function sint32() {
|
|
const r4 = this.uint32();
|
|
return r4 >>> 1 ^ -(1 & r4);
|
|
}
|
|
}, {
|
|
key: "int64",
|
|
value: function int64() {
|
|
return new PbLong(...[...this.varint64()]);
|
|
}
|
|
}, {
|
|
key: "uint64",
|
|
value: function uint64() {
|
|
return new PbULong(...[...this.varint64()]);
|
|
}
|
|
}, {
|
|
key: "sint64",
|
|
value: function sint64() {
|
|
const [r15, r16] = this.varint64();
|
|
const r2 = -(1 & r15);
|
|
return new PbLong((r15 >>> 1 | (1 & r16) << 31) ^ r2, r16 >>> 1 ^ r2);
|
|
}
|
|
}, {
|
|
key: "bool",
|
|
value: function bool() {
|
|
const [r9, r10] = this.varint64();
|
|
return r9 !== 0 || r10 !== 0;
|
|
}
|
|
}, {
|
|
key: "fixed32",
|
|
value: function fixed32() {
|
|
const view = this.view;
|
|
const pos = this.pos + 4;
|
|
this.pos = pos;
|
|
return view.getUint32(pos - 4, true);
|
|
}
|
|
}, {
|
|
key: "sfixed32",
|
|
value: function sfixed32() {
|
|
const view = this.view;
|
|
const pos = this.pos + 4;
|
|
this.pos = pos;
|
|
return view.getInt32(pos - 4, true);
|
|
}
|
|
}, {
|
|
key: "fixed64",
|
|
value: function fixed64() {
|
|
return new PbULong(this.sfixed32(), this.sfixed32());
|
|
}
|
|
}, {
|
|
key: "sfixed64",
|
|
value: function sfixed64() {
|
|
return new PbLong(this.sfixed32(), this.sfixed32());
|
|
}
|
|
}, {
|
|
key: "float",
|
|
value: function float() {
|
|
const view = this.view;
|
|
const pos = this.pos + 4;
|
|
this.pos = pos;
|
|
return view.getFloat32(pos - 4, true);
|
|
}
|
|
}, {
|
|
key: "double",
|
|
value: function double() {
|
|
const view = this.view;
|
|
const pos = this.pos + 8;
|
|
this.pos = pos;
|
|
return view.getFloat64(pos - 8, true);
|
|
}
|
|
}, {
|
|
key: "bytes",
|
|
value: function bytes() {
|
|
const r4 = this.uint32();
|
|
const pos = this.pos;
|
|
this.pos = this.pos + r4;
|
|
this.assertBounds();
|
|
return this.buf.subarray(pos, pos + r4);
|
|
}
|
|
}, {
|
|
key: "string",
|
|
value: function string() {
|
|
return this.textDecoder.decode(this.bytes());
|
|
}
|
|
}]);
|
|
export { c1080_5 as BinaryReader };
|