@snap/camera-kit
Version:
Camera Kit Web
206 lines • 7.61 kB
JavaScript
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
import { Timestamp } from "../../google/protobuf/timestamp";
export const protobufPackage = "snapchat.cdp.cof";
function createBaseBenchmarkValue() {
return { intValue: undefined, longValue: undefined, boolValue: undefined, floatValue: undefined };
}
export const BenchmarkValue = {
encode(message, writer = new BinaryWriter()) {
if (message.intValue !== undefined) {
writer.uint32(8).int32(message.intValue);
}
if (message.longValue !== undefined) {
writer.uint32(16).int64(message.longValue);
}
if (message.boolValue !== undefined) {
writer.uint32(24).bool(message.boolValue);
}
if (message.floatValue !== undefined) {
writer.uint32(37).float(message.floatValue);
}
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 = createBaseBenchmarkValue();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (tag !== 8) {
break;
}
message.intValue = reader.int32();
continue;
}
case 2: {
if (tag !== 16) {
break;
}
message.longValue = reader.int64().toString();
continue;
}
case 3: {
if (tag !== 24) {
break;
}
message.boolValue = reader.bool();
continue;
}
case 4: {
if (tag !== 37) {
break;
}
message.floatValue = reader.float();
continue;
}
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
create(base) {
return BenchmarkValue.fromPartial(base !== null && base !== void 0 ? base : {});
},
fromPartial(object) {
var _a, _b, _c, _d;
const message = createBaseBenchmarkValue();
message.intValue = (_a = object.intValue) !== null && _a !== void 0 ? _a : undefined;
message.longValue = (_b = object.longValue) !== null && _b !== void 0 ? _b : undefined;
message.boolValue = (_c = object.boolValue) !== null && _c !== void 0 ? _c : undefined;
message.floatValue = (_d = object.floatValue) !== null && _d !== void 0 ? _d : undefined;
return message;
},
};
function createBaseBenchmarkRequest() {
return { benchmarkNames: [], expirationTimestamp: undefined };
}
export const BenchmarkRequest = {
encode(message, writer = new BinaryWriter()) {
writer.uint32(10).fork();
for (const v of message.benchmarkNames) {
writer.int32(v);
}
writer.join();
if (message.expirationTimestamp !== undefined) {
Timestamp.encode(toTimestamp(message.expirationTimestamp), writer.uint32(18).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 = createBaseBenchmarkRequest();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (tag === 8) {
message.benchmarkNames.push(reader.int32());
continue;
}
if (tag === 10) {
const end2 = reader.uint32() + reader.pos;
while (reader.pos < end2) {
message.benchmarkNames.push(reader.int32());
}
continue;
}
break;
}
case 2: {
if (tag !== 18) {
break;
}
message.expirationTimestamp = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
continue;
}
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
create(base) {
return BenchmarkRequest.fromPartial(base !== null && base !== void 0 ? base : {});
},
fromPartial(object) {
var _a, _b;
const message = createBaseBenchmarkRequest();
message.benchmarkNames = ((_a = object.benchmarkNames) === null || _a === void 0 ? void 0 : _a.map((e) => e)) || [];
message.expirationTimestamp = (_b = object.expirationTimestamp) !== null && _b !== void 0 ? _b : undefined;
return message;
},
};
function createBaseBenchmarkResult() {
return { name: 0, value: undefined };
}
export const BenchmarkResult = {
encode(message, writer = new BinaryWriter()) {
if (message.name !== 0) {
writer.uint32(8).int32(message.name);
}
if (message.value !== undefined) {
BenchmarkValue.encode(message.value, writer.uint32(18).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 = createBaseBenchmarkResult();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (tag !== 8) {
break;
}
message.name = reader.int32();
continue;
}
case 2: {
if (tag !== 18) {
break;
}
message.value = BenchmarkValue.decode(reader, reader.uint32());
continue;
}
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
create(base) {
return BenchmarkResult.fromPartial(base !== null && base !== void 0 ? base : {});
},
fromPartial(object) {
var _a;
const message = createBaseBenchmarkResult();
message.name = (_a = object.name) !== null && _a !== void 0 ? _a : 0;
message.value = (object.value !== undefined && object.value !== null)
? BenchmarkValue.fromPartial(object.value)
: undefined;
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=benchmark.js.map