UNPKG

@mapeo/schema

Version:

JSON schema and flow types for Mapeo

113 lines (112 loc) 3.82 kB
/* eslint-disable */ import _m0 from "protobufjs/minimal.js"; import { Any } from "../google/protobuf/any.js"; export const protobufPackage = "mapeo"; function createBaseField_1() { return { id: Buffer.alloc(0), key: undefined, type: "" }; } export const Field_1 = { encode(message, writer = _m0.Writer.create()) { if (message.id.length !== 0) { writer.uint32(10).bytes(message.id); } if (message.key !== undefined) { Any.encode(message.key, writer.uint32(18).fork()).ldelim(); } if (message.type !== "") { writer.uint32(26).string(message.type); } 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 = createBaseField_1(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.id = reader.bytes(); break; case 2: message.key = Any.decode(reader, reader.uint32()); break; case 3: message.type = reader.string(); break; default: reader.skipType(tag & 7); break; } } return message; }, fromJSON(object) { return { id: isSet(object.id) ? Buffer.from(bytesFromBase64(object.id)) : Buffer.alloc(0), key: isSet(object.key) ? Any.fromJSON(object.key) : undefined, type: isSet(object.type) ? String(object.type) : "", }; }, toJSON(message) { const obj = {}; message.id !== undefined && (obj.id = base64FromBytes(message.id !== undefined ? message.id : Buffer.alloc(0))); message.key !== undefined && (obj.key = message.key ? Any.toJSON(message.key) : undefined); message.type !== undefined && (obj.type = message.type); return obj; }, create(base) { return Field_1.fromPartial(base !== null && base !== void 0 ? base : {}); }, fromPartial(object) { var _a, _b; const message = createBaseField_1(); message.id = (_a = object.id) !== null && _a !== void 0 ? _a : Buffer.alloc(0); message.key = (object.key !== undefined && object.key !== null) ? Any.fromPartial(object.key) : undefined; message.type = (_b = object.type) !== null && _b !== void 0 ? _b : ""; 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; }