package org.openlca.geo.geojson;

import java.io.IOException;

import org.openlca.util.BinUtils;
import org.openlca.util.Exceptions;

public class ProtoPack {

	private ProtoPack() {
	}

	/**
	 * Converts the given feature collection into a protocol buffer format and
	 * compresses it with gzip. This is the format that we use for storing
	 * geographic data of locations in an openLCA database.
	 */
	public static byte[] packgz(FeatureCollection coll) {
		try {
			byte[] data = pack(coll);
			return BinUtils.gzip(data);
		} catch (IOException e) {
			Exceptions.unchecked(e);
			return null;
		}
	}

	public static byte[] pack(FeatureCollection coll) {
		var proto = Proto.FeatureCollection.newBuilder();
		for (var feature : coll.features) {
		}
		return proto.build().toByteArray();
	}

	private static Proto.Feature pack(Feature feature) {
		var proto = Proto.Feature.newBuilder();

		return proto.build();
	}

	private static Proto.Geometry pack(Geometry g) {
		var proto = Proto.Geometry.newBuilder();
		if (g instanceof Point) {

		}
		return proto.build();
	}
}

@@ -1033,20 +1033,1536 @@
 oint) %7B%0A
-%0A%09%09%7D
+%09%09%09proto.setPoint(pack((Point) g));%0A%09%09%7D%0A%09%09// TODO: type branches%0A%09%09return proto.build();%0A%09%7D%0A%0A%09private static Proto.Point pack(Point point) %7B%0A%09%09var proto = Proto.Point.newBuilder();%0A%09%09proto.setX(point.x);%0A%09%09proto.setY(point.y);%0A%09%09return proto.build();%0A%09%7D%0A%0A%09private static Proto.MultiPoint pack(MultiPoint multiPoint) %7B%0A%09%09var proto = Proto.MultiPoint.newBuilder();%0A%09%09for (var point : multiPoint.points) %7B%0A%09%09%09proto.addPoint(pack(point));%0A%09%09%7D%0A%09%09return proto.build();%0A%09%7D%0A%0A%09private static Proto.LineString pack(LineString lineString) %7B%0A%09%09var proto = Proto.LineString.newBuilder();%0A%09%09for (var point : lineString.points) %7B%0A%09%09%09proto.addPoint(pack(point));%0A%09%09%7D%0A%09%09return proto.build();%0A%09%7D%0A%0A%09private static Proto.MultiLineString pack(MultiLineString multiLineString) %7B%0A%09%09var proto = Proto.MultiLineString.newBuilder();%0A%09%09for (var lineString : multiLineString.lineStrings) %7B%0A%09%09%09proto.addLineString(pack(lineString));%0A%09%09%7D%0A%09%09return proto.build();%0A%09%7D%0A%0A%09private static Proto.Polygon pack(Polygon polygon) %7B%0A%09%09var proto = Proto.Polygon.newBuilder();%0A%09%09for (var ring : polygon.rings) %7B%0A%09%09%09proto.addRing(pack(ring));%0A%09%09%7D%0A%09%09return proto.build();%0A%09%7D%0A%0A%09private static Proto.MultiPolygon pack(MultiPolygon multiPolygon) %7B%0A%09%09var proto = Proto.MultiPolygon.newBuilder();%0A%09%09for (var polygon : multiPolygon.polygons) %7B%0A%09%09%09proto.addPolygon(pack(polygon));%0A%09%09%7D%0A%09%09return proto.build();%0A%09%7D%0A%0A%09private static Proto.GeometryCollection pack(GeometryCollection geometryCollection) %7B%0A%09%09var proto = Proto.GeometryCollection.newBuilder();%0A%09%09// TODO: map values
 %0A%09%09retur

create package stubs