146 lines
4.9 KiB
JavaScript
146 lines
4.9 KiB
JavaScript
// Metro module 1336 (f1337).
|
|
import { MessageType, PbLong, typeofJsonValue, MESSAGE_TYPE, reflectionMergePartial, UnknownFieldHandler, WireType } from "./Module1307";
|
|
import { $callWithNewTarget } from "../_hermes/prelude";
|
|
class Timestamp$Type extends MessageType {
|
|
constructor() {
|
|
const r2 = [{
|
|
no: 1,
|
|
name: "seconds",
|
|
kind: "scalar",
|
|
T: 3
|
|
}, {
|
|
no: 2,
|
|
name: "nanos",
|
|
kind: "scalar",
|
|
T: 5
|
|
}];
|
|
super("google.protobuf.Timestamp", r2);
|
|
}
|
|
now() {
|
|
const r9 = this.create();
|
|
const r11 = Date.now();
|
|
r9.seconds = PbLong.from(Math.floor(r11 / 1000)).toString();
|
|
r9.nanos = r11 % 1000 * 1000000;
|
|
return r9;
|
|
}
|
|
toDate(a0) {
|
|
return new Date(1000 * PbLong.from(a0.seconds).toNumber() + Math.ceil(a0.nanos / 1000000));
|
|
}
|
|
fromDate(a0) {
|
|
const r9 = this.create();
|
|
const time = a0.getTime();
|
|
r9.seconds = PbLong.from(Math.floor(time / 1000)).toString();
|
|
r9.nanos = time % 1000 * 1000000;
|
|
return r9;
|
|
}
|
|
internalJsonWrite(a0) {
|
|
const r23 = 1000 * PbLong.from(a0.seconds).toNumber();
|
|
if (!(r23 < Date.parse("0001-01-01T00:00:00Z")) && !(r23 > Date.parse("9999-12-31T23:59:59Z"))) {
|
|
if (a0.nanos < 0) {
|
|
throw new Error("Unable to encode invalid Timestamp to JSON. Nanos must not be negative.");
|
|
}
|
|
const r34 = a0.nanos > 0;
|
|
let r36 = "Z";
|
|
if (r34) {
|
|
const r10 = (a0.nanos + 1000000000).toString().substring(1);
|
|
r36 = r10.substring(3) === "000000" ? "." + r10.substring(0, 3) + "Z" : r10.substring(6) === "000" ? "." + r10.substring(0, 6) + "Z" : "." + r10 + "Z";
|
|
}
|
|
return new Date(r23).toISOString().replace(".000Z", r36);
|
|
}
|
|
throw new Error("Unable to encode Timestamp to JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.");
|
|
}
|
|
internalJsonRead(a0, a1, a2) {
|
|
if (typeof a0 !== "string") {
|
|
throw new Error("Unable to parse Timestamp from JSON " + typeofJsonValue(a0) + ".");
|
|
}
|
|
const r10 = a0.match(/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:Z|\.([0-9]{3,9})Z|([+-][0-9][0-9]:[0-9][0-9]))$/);
|
|
if (r10) {
|
|
const r38 = Date.parse(r10[1] + "-" + r10[2] + "-" + r10[3] + "T" + r10[4] + ":" + r10[5] + ":" + r10[6] + (r10[8] ? r10[8] : "Z"));
|
|
if (Number.isNaN(r38)) {
|
|
throw new Error("Unable to parse Timestamp from JSON. Invalid value.");
|
|
}
|
|
if (!(r38 < Date.parse("0001-01-01T00:00:00Z")) && !(r38 > Date.parse("9999-12-31T23:59:59Z"))) {
|
|
const r50 = a2 ? a2 : this.create();
|
|
r50.seconds = PbLong.from(r38 / 1000).toString();
|
|
r50.nanos = 0;
|
|
if (r10[7]) {
|
|
r50.nanos = parseInt("1" + r10[7] + "0".repeat(9 - r10[7].length)) - 1000000000;
|
|
}
|
|
return r50;
|
|
}
|
|
throw new globalThis.globalThis.Error("Unable to parse Timestamp from JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.");
|
|
}
|
|
throw new Error("Unable to parse Timestamp from JSON. Invalid format.");
|
|
}
|
|
create(a0) {
|
|
const r1 = {
|
|
seconds: "0",
|
|
nanos: 0
|
|
};
|
|
globalThis.globalThis.Object.defineProperty(r1, MESSAGE_TYPE, {
|
|
enumerable: false,
|
|
value: this
|
|
});
|
|
if (a0 !== void 0) {
|
|
reflectionMergePartial(this, r1, a0);
|
|
}
|
|
return r1;
|
|
}
|
|
internalBinaryRead(a0, a1, a2, a3) {
|
|
const r5 = a3 == null ? this.create() : a3;
|
|
const r8 = a0.pos + a1;
|
|
while (a0.pos < r8) {
|
|
const [r19, r18] = a0.tag();
|
|
if (r19 === 1) {
|
|
r5.seconds = a0.int64().toString();
|
|
} else if (r19 === 2) {
|
|
r5.nanos = a0.int32();
|
|
} else {
|
|
let readUnknownField = a2.readUnknownField;
|
|
if (readUnknownField === "throw") {
|
|
throw new globalThis.globalThis.Error(`Unknown field ${r19} (wire type ${r18}) for ${this.typeName}`);
|
|
}
|
|
const r34 = a0.skip(r18);
|
|
if (readUnknownField !== false) {
|
|
if (readUnknownField === true) {
|
|
readUnknownField = UnknownFieldHandler.onRead;
|
|
}
|
|
readUnknownField(this.typeName, r5, r19, r18, r34);
|
|
}
|
|
}
|
|
}
|
|
return r5;
|
|
}
|
|
internalBinaryWrite(a0, a1, a2) {
|
|
if (a0.seconds !== "0") {
|
|
a1.tag(1, WireType.Varint).int64(a0.seconds);
|
|
}
|
|
if (a0.nanos !== 0) {
|
|
a1.tag(2, WireType.Varint).int32(a0.nanos);
|
|
}
|
|
let writeUnknownFields = a2.writeUnknownFields;
|
|
if (writeUnknownFields !== false) {
|
|
if (writeUnknownFields == 1) {
|
|
writeUnknownFields = UnknownFieldHandler.onWrite;
|
|
}
|
|
writeUnknownFields(this.typeName, a0, a1);
|
|
}
|
|
return a1;
|
|
}
|
|
}
|
|
const prototypeOf = Object.getPrototypeOf(Timestamp$Type);
|
|
const r42 = [{
|
|
no: 1,
|
|
name: "seconds",
|
|
kind: "scalar",
|
|
T: 3
|
|
}, {
|
|
no: 2,
|
|
name: "nanos",
|
|
kind: "scalar",
|
|
T: 5
|
|
}];
|
|
const r44 = Object.create(Timestamp$Type.prototype);
|
|
const r45 = $callWithNewTarget(prototypeOf, r44, Timestamp$Type, "google.protobuf.Timestamp", r42);
|
|
export const Timestamp = r45 instanceof Object ? r45 : r44;
|