UNPKG

@mapeo/schema

Version:

JSON schema and flow types for Mapeo

104 lines (103 loc) 3.31 kB
/* eslint-disable */ import _m0 from "protobufjs/minimal.js"; export const protobufPackage = "google.protobuf"; function createBaseAny() { return { type_url: "", value: Buffer.alloc(0) }; } export const Any = { encode(message, writer = _m0.Writer.create()) { if (message.type_url !== "") { writer.uint32(10).string(message.type_url); } if (message.value.length !== 0) { writer.uint32(18).bytes(message.value); } return writer; }, decode(input, length) { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(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: message.type_url = reader.string(); break; case 2: message.value = reader.bytes(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromJSON(object) { return { type_url: isSet(object.type_url) ? String(object.type_url) : "", value: isSet(object.value) ? Buffer.from(bytesFromBase64(object.value)) : Buffer.alloc(0), }; }, toJSON(message) { const obj = {}; message.type_url !== undefined && (obj.type_url = message.type_url); message.value !== undefined && (obj.value = base64FromBytes(message.value !== undefined ? message.value : Buffer.alloc(0))); 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 : Buffer.alloc(0); return message; }, }; var tsProtoGlobalThis = (() => { if (typeof globalThis !== "undefined") { return globalThis; } if (typeof self !== "undefined") { return self; } if (typeof window !== "undefined") { return window; } if (typeof global !== "undefined") { return global; } throw "Unable to locate global object"; })(); function bytesFromBase64(b64) { if (tsProtoGlobalThis.Buffer) { return Uint8Array.from(tsProtoGlobalThis.Buffer.from(b64, "base64")); } else { const bin = tsProtoGlobalThis.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 (tsProtoGlobalThis.Buffer) { return tsProtoGlobalThis.Buffer.from(arr).toString("base64"); } else { const bin = []; arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); }); return tsProtoGlobalThis.btoa(bin.join("")); } } function isSet(value) { return value !== null && value !== undefined; }