225 lines
5.2 KiB
JavaScript
225 lines
5.2 KiB
JavaScript
// Metro module 1315 (f1316).
|
|
import * as _classCallCheck from "./_classCallCheck";
|
|
import * as __createClass from "./_createClass";
|
|
import { assertUInt32, assertInt32, assertFloat32 } from "./Module1316";
|
|
import { varint32write, varint64write } from "./Module1313";
|
|
import { PbLong, PbULong } from "./SharedPbLong";
|
|
let c1087_4;
|
|
let BinaryWriter;
|
|
let env1087 = {};
|
|
const c1087_3 = {
|
|
writeUnknownFields: true,
|
|
writerFactory: () => new c1087_4()
|
|
};
|
|
export function binaryWriteOptions(a0) {
|
|
return a0 ? {
|
|
...c1087_3,
|
|
...a0
|
|
} : c1087_3;
|
|
}
|
|
BinaryWriter = function BinaryWriter(a0) {
|
|
let textEncoder = a0;
|
|
_classCallCheck(this, BinaryWriter);
|
|
this.stack = [];
|
|
if (a0 == null) {
|
|
textEncoder = new TextEncoder();
|
|
}
|
|
this.textEncoder = textEncoder;
|
|
this.chunks = [];
|
|
this.buf = [];
|
|
};
|
|
c1087_4 = __createClass(BinaryWriter, [{
|
|
key: "finish",
|
|
value: function finish() {
|
|
let length;
|
|
this.chunks.push(new Uint8Array(this.buf));
|
|
const r4 = 0 < this.chunks.length;
|
|
let r0 = 0;
|
|
let r19 = 0;
|
|
let r20 = 0;
|
|
if (r4) {
|
|
do {
|
|
r19 = r19 + this.chunks[r0].length;
|
|
r0 = r0 + 1;
|
|
length = this.chunks.length;
|
|
r20 = r19;
|
|
} while (r0 < length);
|
|
}
|
|
const uint8Array = new Uint8Array(r20);
|
|
const r34 = 0 < this.chunks.length;
|
|
let r35 = 0;
|
|
let r36 = 0;
|
|
if (r34) {
|
|
do {
|
|
uint8Array.set(this.chunks[r35], r36);
|
|
r36 = r36 + this.chunks[r35].length;
|
|
r35 = r35 + 1;
|
|
} while (r35 < this.chunks.length);
|
|
}
|
|
this.chunks = [];
|
|
return uint8Array;
|
|
}
|
|
}, {
|
|
key: "fork",
|
|
value: function fork() {
|
|
this.stack.push({
|
|
chunks: this.chunks,
|
|
buf: this.buf
|
|
});
|
|
this.chunks = [];
|
|
this.buf = [];
|
|
return this;
|
|
}
|
|
}, {
|
|
key: "join",
|
|
value: function join() {
|
|
const r1 = this.finish();
|
|
const r9 = this.stack.pop();
|
|
if (r9) {
|
|
this.chunks = r9.chunks;
|
|
this.buf = r9.buf;
|
|
this.uint32(r1.byteLength);
|
|
return this.raw(r1);
|
|
}
|
|
throw new Error("invalid state, fork stack empty");
|
|
}
|
|
}, {
|
|
key: "tag",
|
|
value: function tag(a0, a1) {
|
|
return this.uint32((a0 << 3 | a1) >>> 0);
|
|
}
|
|
}, {
|
|
key: "raw",
|
|
value: function raw(a0) {
|
|
if (this.buf.length) {
|
|
this.chunks.push(new Uint8Array(this.buf));
|
|
this.buf = [];
|
|
}
|
|
this.chunks.push(a0);
|
|
return this;
|
|
}
|
|
}, {
|
|
key: "uint32",
|
|
value: function uint32(a0) {
|
|
assertUInt32(a0);
|
|
let r15 = a0;
|
|
let r16 = a0;
|
|
if (a0 > 127) {
|
|
do {
|
|
this.buf.push(127 & r15 | 128);
|
|
r15 = r15 >>> 7;
|
|
r16 = r15;
|
|
} while (127 < r16);
|
|
}
|
|
this.buf.push(r16);
|
|
return this;
|
|
}
|
|
}, {
|
|
key: "int32",
|
|
value: function int32(a0) {
|
|
assertInt32(a0);
|
|
varint32write(a0, this.buf);
|
|
return this;
|
|
}
|
|
}, {
|
|
key: "bool",
|
|
value: function bool(a0) {
|
|
this.buf.push(a0 ? 1 : 0);
|
|
return this;
|
|
}
|
|
}, {
|
|
key: "bytes",
|
|
value: function bytes(a0) {
|
|
this.uint32(a0.byteLength);
|
|
return this.raw(a0);
|
|
}
|
|
}, {
|
|
key: "string",
|
|
value: function string(a0) {
|
|
const r4 = this.textEncoder.encode(a0);
|
|
this.uint32(r4.byteLength);
|
|
return this.raw(r4);
|
|
}
|
|
}, {
|
|
key: "float",
|
|
value: function float(a0) {
|
|
assertFloat32(a0);
|
|
const uint8Array = new Uint8Array(4);
|
|
new DataView(uint8Array.buffer).setFloat32(0, a0, true);
|
|
return this.raw(uint8Array);
|
|
}
|
|
}, {
|
|
key: "double",
|
|
value: function double(a0) {
|
|
const uint8Array = new Uint8Array(8);
|
|
new DataView(uint8Array.buffer).setFloat64(0, a0, true);
|
|
return this.raw(uint8Array);
|
|
}
|
|
}, {
|
|
key: "fixed32",
|
|
value: function fixed32(a0) {
|
|
assertUInt32(a0);
|
|
const uint8Array = new Uint8Array(4);
|
|
new DataView(uint8Array.buffer).setUint32(0, a0, true);
|
|
return this.raw(uint8Array);
|
|
}
|
|
}, {
|
|
key: "sfixed32",
|
|
value: function sfixed32(a0) {
|
|
assertInt32(a0);
|
|
const uint8Array = new Uint8Array(4);
|
|
new DataView(uint8Array.buffer).setInt32(0, a0, true);
|
|
return this.raw(uint8Array);
|
|
}
|
|
}, {
|
|
key: "sint32",
|
|
value: function sint32(a0) {
|
|
assertInt32(a0);
|
|
varint32write((a0 << 1 ^ a0 >> 31) >>> 0, this.buf);
|
|
return this;
|
|
}
|
|
}, {
|
|
key: "sfixed64",
|
|
value: function sfixed64(a0) {
|
|
const uint8Array = new Uint8Array(8);
|
|
const dataView = new DataView(uint8Array.buffer);
|
|
const r26 = PbLong.from(a0);
|
|
dataView.setInt32(0, r26.lo, true);
|
|
dataView.setInt32(4, r26.hi, true);
|
|
return this.raw(uint8Array);
|
|
}
|
|
}, {
|
|
key: "fixed64",
|
|
value: function fixed64(a0) {
|
|
const uint8Array = new Uint8Array(8);
|
|
const dataView = new DataView(uint8Array.buffer);
|
|
const r26 = PbULong.from(a0);
|
|
dataView.setInt32(0, r26.lo, true);
|
|
dataView.setInt32(4, r26.hi, true);
|
|
return this.raw(uint8Array);
|
|
}
|
|
}, {
|
|
key: "int64",
|
|
value: function int64(a0) {
|
|
const r10 = PbLong.from(a0);
|
|
varint64write(r10.lo, r10.hi, this.buf);
|
|
return this;
|
|
}
|
|
}, {
|
|
key: "sint64",
|
|
value: function sint64(a0) {
|
|
const r14 = PbLong.from(a0);
|
|
const r3 = r14.hi >> 31;
|
|
varint64write(r14.lo << 1 ^ r3, (r14.hi << 1 | r14.lo >>> 31) ^ r3, this.buf);
|
|
return this;
|
|
}
|
|
}, {
|
|
key: "uint64",
|
|
value: function uint64(a0) {
|
|
const r10 = PbULong.from(a0);
|
|
varint64write(r10.lo, r10.hi, this.buf);
|
|
return this;
|
|
}
|
|
}]);
|
|
export { c1087_4 as BinaryWriter };
|