UNPKG

@snap/camera-kit

Version:
155 lines 6.5 kB
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire"; import { Timestamp } from "../../google/protobuf/timestamp"; export const protobufPackage = "com.snap.camerakit.v3"; function createBaseOperationalMetric() { return { name: "", timestamp: undefined, metric: undefined }; } export const OperationalMetric = { encode(message, writer = new BinaryWriter()) { var _a; if (message.name !== "") { writer.uint32(10).string(message.name); } if (message.timestamp !== undefined) { Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(18).fork()).join(); } switch ((_a = message.metric) === null || _a === void 0 ? void 0 : _a.$case) { case "count": writer.uint32(24).uint64(message.metric.count); break; case "latencyMillis": writer.uint32(32).uint64(message.metric.latencyMillis); break; case "histogram": writer.uint32(40).int64(message.metric.histogram); break; } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseOperationalMetric(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: { if (tag !== 10) { break; } message.name = reader.string(); continue; } case 2: { if (tag !== 18) { break; } message.timestamp = fromTimestamp(Timestamp.decode(reader, reader.uint32())); continue; } case 3: { if (tag !== 24) { break; } message.metric = { $case: "count", count: reader.uint64().toString() }; continue; } case 4: { if (tag !== 32) { break; } message.metric = { $case: "latencyMillis", latencyMillis: reader.uint64().toString() }; continue; } case 5: { if (tag !== 40) { break; } message.metric = { $case: "histogram", histogram: reader.int64().toString() }; continue; } } if ((tag & 7) === 4 || tag === 0) { break; } reader.skip(tag & 7); } return message; }, create(base) { return OperationalMetric.fromPartial(base !== null && base !== void 0 ? base : {}); }, fromPartial(object) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; const message = createBaseOperationalMetric(); message.name = (_a = object.name) !== null && _a !== void 0 ? _a : ""; message.timestamp = (_b = object.timestamp) !== null && _b !== void 0 ? _b : undefined; if (((_c = object.metric) === null || _c === void 0 ? void 0 : _c.$case) === "count" && ((_d = object.metric) === null || _d === void 0 ? void 0 : _d.count) !== undefined && ((_e = object.metric) === null || _e === void 0 ? void 0 : _e.count) !== null) { message.metric = { $case: "count", count: object.metric.count }; } if (((_f = object.metric) === null || _f === void 0 ? void 0 : _f.$case) === "latencyMillis" && ((_g = object.metric) === null || _g === void 0 ? void 0 : _g.latencyMillis) !== undefined && ((_h = object.metric) === null || _h === void 0 ? void 0 : _h.latencyMillis) !== null) { message.metric = { $case: "latencyMillis", latencyMillis: object.metric.latencyMillis }; } if (((_j = object.metric) === null || _j === void 0 ? void 0 : _j.$case) === "histogram" && ((_k = object.metric) === null || _k === void 0 ? void 0 : _k.histogram) !== undefined && ((_l = object.metric) === null || _l === void 0 ? void 0 : _l.histogram) !== null) { message.metric = { $case: "histogram", histogram: object.metric.histogram }; } return message; }, }; function createBaseOperationalMetricsBundle() { return { metrics: [] }; } export const OperationalMetricsBundle = { encode(message, writer = new BinaryWriter()) { for (const v of message.metrics) { OperationalMetric.encode(v, writer.uint32(10).fork()).join(); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseOperationalMetricsBundle(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: { if (tag !== 10) { break; } message.metrics.push(OperationalMetric.decode(reader, reader.uint32())); continue; } } if ((tag & 7) === 4 || tag === 0) { break; } reader.skip(tag & 7); } return message; }, create(base) { return OperationalMetricsBundle.fromPartial(base !== null && base !== void 0 ? base : {}); }, fromPartial(object) { var _a; const message = createBaseOperationalMetricsBundle(); message.metrics = ((_a = object.metrics) === null || _a === void 0 ? void 0 : _a.map((e) => OperationalMetric.fromPartial(e))) || []; return message; }, }; function toTimestamp(date) { const seconds = Math.trunc(date.getTime() / 1000).toString(); const nanos = (date.getTime() % 1000) * 1000000; return { seconds, nanos }; } function fromTimestamp(t) { let millis = (globalThis.Number(t.seconds) || 0) * 1000; millis += (t.nanos || 0) / 1000000; return new globalThis.Date(millis); } //# sourceMappingURL=operational_metrics.js.map