UNPKG

@htdangkhoa/google-ads

Version:
103 lines (102 loc) 3.36 kB
// Code generated by protoc-gen-ts_proto. DO NOT EDIT. // versions: // protoc-gen-ts_proto v1.181.2 // protoc v3.21.12 // source: google/protobuf/any.proto /* eslint-disable */ import _m0 from "protobufjs/minimal.js"; function createBaseAny() { return { type_url: "", value: new Uint8Array(0) }; } export const Any = { encode(message, writer = _m0.Writer.create()) { if (message.type_url !== undefined && message.type_url !== "") { writer.uint32(10).string(message.type_url); } if (message.value !== undefined && message.value.length !== 0) { writer.uint32(18).bytes(message.value); } return writer; }, decode(input, length) { const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseAny(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: if (tag !== 10) { break; } message.type_url = reader.string(); continue; case 2: if (tag !== 18) { break; } message.value = reader.bytes(); continue; } if ((tag & 7) === 4 || tag === 0) { break; } reader.skipType(tag & 7); } return message; }, fromJSON(object) { return { type_url: isSet(object.type_url) ? globalThis.String(object.type_url) : "", value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), }; }, toJSON(message) { const obj = {}; if (message.type_url !== undefined && message.type_url !== "") { obj.type_url = message.type_url; } if (message.value !== undefined && message.value.length !== 0) { obj.value = base64FromBytes(message.value); } return obj; }, create(base) { return Any.fromPartial(base !== null && base !== void 0 ? base : {}); }, fromPartial(object) { var _a, _b; const message = createBaseAny(); message.type_url = (_a = object.type_url) !== null && _a !== void 0 ? _a : ""; message.value = (_b = object.value) !== null && _b !== void 0 ? _b : new Uint8Array(0); return message; }, }; function bytesFromBase64(b64) { if (globalThis.Buffer) { return Uint8Array.from(globalThis.Buffer.from(b64, "base64")); } else { const bin = globalThis.atob(b64); const arr = new Uint8Array(bin.length); for (let i = 0; i < bin.length; ++i) { arr[i] = bin.charCodeAt(i); } return arr; } } function base64FromBytes(arr) { if (globalThis.Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin = []; arr.forEach((byte) => { bin.push(globalThis.String.fromCharCode(byte)); }); return globalThis.btoa(bin.join("")); } } function isSet(value) { return value !== null && value !== undefined; }