@mapeo/schema
Version:
JSON schema and flow types for Mapeo
251 lines (250 loc) • 10.2 kB
JavaScript
/* eslint-disable */
import _m0 from "protobufjs/minimal.js";
import { Common_1 } from "../common/v1.js";
import { Struct } from "../google/protobuf/struct.js";
export const protobufPackage = "mapeo";
function createBaseObservation_5() {
return {
common: undefined,
lat: undefined,
lon: undefined,
refs: [],
attachments: [],
tags: undefined,
metadata: undefined,
};
}
export const Observation_5 = {
encode(message, writer = _m0.Writer.create()) {
if (message.common !== undefined) {
Common_1.encode(message.common, writer.uint32(10).fork()).ldelim();
}
if (message.lat !== undefined) {
writer.uint32(21).float(message.lat);
}
if (message.lon !== undefined) {
writer.uint32(29).float(message.lon);
}
for (const v of message.refs) {
Struct.encode(Struct.wrap(v), writer.uint32(34).fork()).ldelim();
}
for (const v of message.attachments) {
Struct.encode(Struct.wrap(v), writer.uint32(42).fork()).ldelim();
}
if (message.tags !== undefined) {
Struct.encode(Struct.wrap(message.tags), writer.uint32(50).fork()).ldelim();
}
if (message.metadata !== undefined) {
Observation_5_Metadata.encode(message.metadata, writer.uint32(58).fork()).ldelim();
}
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 = createBaseObservation_5();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.common = Common_1.decode(reader, reader.uint32());
break;
case 2:
message.lat = reader.float();
break;
case 3:
message.lon = reader.float();
break;
case 4:
message.refs.push(Struct.unwrap(Struct.decode(reader, reader.uint32())));
break;
case 5:
message.attachments.push(Struct.unwrap(Struct.decode(reader, reader.uint32())));
break;
case 6:
message.tags = Struct.unwrap(Struct.decode(reader, reader.uint32()));
break;
case 7:
message.metadata = Observation_5_Metadata.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object) {
return {
common: isSet(object.common) ? Common_1.fromJSON(object.common) : undefined,
lat: isSet(object.lat) ? Number(object.lat) : undefined,
lon: isSet(object.lon) ? Number(object.lon) : undefined,
refs: Array.isArray(object === null || object === void 0 ? void 0 : object.refs) ? [...object.refs] : [],
attachments: Array.isArray(object === null || object === void 0 ? void 0 : object.attachments) ? [...object.attachments] : [],
tags: isObject(object.tags) ? object.tags : undefined,
metadata: isSet(object.metadata) ? Observation_5_Metadata.fromJSON(object.metadata) : undefined,
};
},
toJSON(message) {
const obj = {};
message.common !== undefined && (obj.common = message.common ? Common_1.toJSON(message.common) : undefined);
message.lat !== undefined && (obj.lat = message.lat);
message.lon !== undefined && (obj.lon = message.lon);
if (message.refs) {
obj.refs = message.refs.map((e) => e);
}
else {
obj.refs = [];
}
if (message.attachments) {
obj.attachments = message.attachments.map((e) => e);
}
else {
obj.attachments = [];
}
message.tags !== undefined && (obj.tags = message.tags);
message.metadata !== undefined &&
(obj.metadata = message.metadata ? Observation_5_Metadata.toJSON(message.metadata) : undefined);
return obj;
},
create(base) {
return Observation_5.fromPartial(base !== null && base !== void 0 ? base : {});
},
fromPartial(object) {
var _a, _b, _c, _d, _e;
const message = createBaseObservation_5();
message.common = (object.common !== undefined && object.common !== null)
? Common_1.fromPartial(object.common)
: undefined;
message.lat = (_a = object.lat) !== null && _a !== void 0 ? _a : undefined;
message.lon = (_b = object.lon) !== null && _b !== void 0 ? _b : undefined;
message.refs = ((_c = object.refs) === null || _c === void 0 ? void 0 : _c.map((e) => e)) || [];
message.attachments = ((_d = object.attachments) === null || _d === void 0 ? void 0 : _d.map((e) => e)) || [];
message.tags = (_e = object.tags) !== null && _e !== void 0 ? _e : undefined;
message.metadata = (object.metadata !== undefined && object.metadata !== null)
? Observation_5_Metadata.fromPartial(object.metadata)
: undefined;
return message;
},
};
function createBaseObservation_5_Metadata() {
return { location: undefined, manual_location: undefined };
}
export const Observation_5_Metadata = {
encode(message, writer = _m0.Writer.create()) {
if (message.location !== undefined) {
Observation_5_Metadata_Location.encode(message.location, writer.uint32(10).fork()).ldelim();
}
if (message.manual_location !== undefined) {
writer.uint32(16).bool(message.manual_location);
}
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 = createBaseObservation_5_Metadata();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.location = Observation_5_Metadata_Location.decode(reader, reader.uint32());
break;
case 2:
message.manual_location = reader.bool();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object) {
return {
location: isSet(object.location) ? Observation_5_Metadata_Location.fromJSON(object.location) : undefined,
manual_location: isSet(object.manual_location) ? Boolean(object.manual_location) : undefined,
};
},
toJSON(message) {
const obj = {};
message.location !== undefined &&
(obj.location = message.location ? Observation_5_Metadata_Location.toJSON(message.location) : undefined);
message.manual_location !== undefined && (obj.manual_location = message.manual_location);
return obj;
},
create(base) {
return Observation_5_Metadata.fromPartial(base !== null && base !== void 0 ? base : {});
},
fromPartial(object) {
var _a;
const message = createBaseObservation_5_Metadata();
message.location = (object.location !== undefined && object.location !== null)
? Observation_5_Metadata_Location.fromPartial(object.location)
: undefined;
message.manual_location = (_a = object.manual_location) !== null && _a !== void 0 ? _a : undefined;
return message;
},
};
function createBaseObservation_5_Metadata_Location() {
return { precision: undefined, altitude: undefined };
}
export const Observation_5_Metadata_Location = {
encode(message, writer = _m0.Writer.create()) {
if (message.precision !== undefined) {
writer.uint32(13).float(message.precision);
}
if (message.altitude !== undefined) {
writer.uint32(16).int32(message.altitude);
}
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 = createBaseObservation_5_Metadata_Location();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.precision = reader.float();
break;
case 2:
message.altitude = reader.int32();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object) {
return {
precision: isSet(object.precision) ? Number(object.precision) : undefined,
altitude: isSet(object.altitude) ? Number(object.altitude) : undefined,
};
},
toJSON(message) {
const obj = {};
message.precision !== undefined && (obj.precision = message.precision);
message.altitude !== undefined && (obj.altitude = Math.round(message.altitude));
return obj;
},
create(base) {
return Observation_5_Metadata_Location.fromPartial(base !== null && base !== void 0 ? base : {});
},
fromPartial(object) {
var _a, _b;
const message = createBaseObservation_5_Metadata_Location();
message.precision = (_a = object.precision) !== null && _a !== void 0 ? _a : undefined;
message.altitude = (_b = object.altitude) !== null && _b !== void 0 ? _b : undefined;
return message;
},
};
function isObject(value) {
return typeof value === "object" && value !== null;
}
function isSet(value) {
return value !== null && value !== undefined;
}