2010-10-27 12:36:07 +02:00
|
|
|
package net.osmand.binary;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2010-10-28 09:52:19 +02:00
|
|
|
import java.io.OutputStream;
|
2010-10-27 22:04:09 +02:00
|
|
|
import java.io.RandomAccessFile;
|
2010-11-02 00:54:41 +01:00
|
|
|
import java.util.Collection;
|
2010-10-27 17:18:28 +02:00
|
|
|
import java.util.LinkedHashMap;
|
2010-11-05 13:11:09 +01:00
|
|
|
import java.util.LinkedHashSet;
|
2010-11-02 00:42:17 +01:00
|
|
|
import java.util.List;
|
2010-10-27 17:18:28 +02:00
|
|
|
import java.util.Map;
|
2010-11-05 13:11:09 +01:00
|
|
|
import java.util.Set;
|
2010-10-27 12:36:07 +02:00
|
|
|
import java.util.Stack;
|
|
|
|
|
2010-10-27 17:18:28 +02:00
|
|
|
import net.osmand.Algoritms;
|
2010-11-02 00:42:17 +01:00
|
|
|
import net.osmand.binary.OsmandOdb.CityIndex;
|
2010-11-03 14:07:14 +01:00
|
|
|
import net.osmand.binary.OsmandOdb.InteresectedStreets;
|
2010-11-05 13:11:09 +01:00
|
|
|
import net.osmand.binary.OsmandOdb.OsmAndTransportIndex;
|
2010-11-02 00:42:17 +01:00
|
|
|
import net.osmand.binary.OsmandOdb.PostcodeIndex;
|
2010-11-01 14:54:52 +01:00
|
|
|
import net.osmand.binary.OsmandOdb.StreetIndex;
|
2010-11-03 14:07:14 +01:00
|
|
|
import net.osmand.binary.OsmandOdb.StreetIntersection;
|
2010-11-05 13:11:09 +01:00
|
|
|
import net.osmand.binary.OsmandOdb.TransportRoute;
|
|
|
|
import net.osmand.binary.OsmandOdb.TransportRouteStop;
|
2010-11-01 14:54:52 +01:00
|
|
|
import net.osmand.data.Building;
|
|
|
|
import net.osmand.data.City;
|
|
|
|
import net.osmand.data.MapObject;
|
|
|
|
import net.osmand.data.Street;
|
2010-11-05 13:11:09 +01:00
|
|
|
import net.osmand.data.TransportStop;
|
2010-10-28 09:52:19 +02:00
|
|
|
import net.osmand.data.index.IndexConstants;
|
2010-11-01 14:54:52 +01:00
|
|
|
import net.osmand.osm.LatLon;
|
|
|
|
import net.osmand.osm.MapUtils;
|
2010-11-03 14:07:14 +01:00
|
|
|
import net.osmand.osm.Node;
|
2010-11-02 00:42:17 +01:00
|
|
|
import net.sf.junidecode.Junidecode;
|
2010-10-27 12:36:07 +02:00
|
|
|
|
|
|
|
import com.google.protobuf.CodedOutputStream;
|
|
|
|
import com.google.protobuf.WireFormat;
|
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
public class BinaryMapIndexWriter {
|
2010-10-27 12:36:07 +02:00
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
private RandomAccessFile raf;
|
2010-10-27 12:36:07 +02:00
|
|
|
private CodedOutputStream codedOutStream;
|
2010-10-30 11:06:21 +02:00
|
|
|
protected static final int SHIFT_COORDINATES = 5;
|
2010-10-27 12:36:07 +02:00
|
|
|
|
|
|
|
private static class Bounds {
|
|
|
|
public Bounds(int leftX, int rightX, int topY, int bottomY) {
|
|
|
|
super();
|
|
|
|
this.bottomY = bottomY;
|
|
|
|
this.leftX = leftX;
|
|
|
|
this.rightX = rightX;
|
|
|
|
this.topY = topY;
|
|
|
|
}
|
|
|
|
int leftX = 0;
|
|
|
|
int rightX = 0;
|
|
|
|
int topY = 0;
|
|
|
|
int bottomY = 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private Stack<Bounds> stackBounds = new Stack<Bounds>();
|
2010-10-27 17:18:28 +02:00
|
|
|
// needed for map tree
|
|
|
|
private Stack<Long> stackBaseIds = new Stack<Long>();
|
|
|
|
private Stack<Map<String, Integer>> stackStringTable = new Stack<Map<String, Integer>>();
|
2010-10-27 12:36:07 +02:00
|
|
|
|
2010-11-01 14:54:52 +01:00
|
|
|
|
2010-10-27 12:36:07 +02:00
|
|
|
// internal constants to track state of index writing
|
|
|
|
private Stack<Integer> state = new Stack<Integer>();
|
2010-10-27 22:04:09 +02:00
|
|
|
private Stack<Long> stackSizes = new Stack<Long>();
|
|
|
|
|
2010-10-27 12:36:07 +02:00
|
|
|
private final static int OSMAND_STRUCTURE_INIT = 1;
|
|
|
|
private final static int MAP_INDEX_INIT = 2;
|
|
|
|
private final static int MAP_ROOT_LEVEL_INIT = 3;
|
|
|
|
private final static int MAP_TREE = 4;
|
2010-11-01 14:54:52 +01:00
|
|
|
|
|
|
|
private final static int ADDRESS_INDEX_INIT = 5;
|
|
|
|
private final static int CITY_INDEX_INIT = 6;
|
|
|
|
private final static int POSTCODES_INDEX_INIT = 7;
|
2010-11-02 00:42:17 +01:00
|
|
|
private final static int VILLAGES_INDEX_INIT = 8;
|
2010-11-05 13:11:09 +01:00
|
|
|
|
|
|
|
private final static int TRANSPORT_INDEX_INIT = 9;
|
|
|
|
private final static int TRANSPORT_STOPS_TREE = 10;
|
2010-10-27 12:36:07 +02:00
|
|
|
|
2010-10-28 09:52:19 +02:00
|
|
|
public BinaryMapIndexWriter(final RandomAccessFile raf) throws IOException{
|
2010-10-27 22:04:09 +02:00
|
|
|
this.raf = raf;
|
2010-10-28 09:52:19 +02:00
|
|
|
codedOutStream = CodedOutputStream.newInstance(new OutputStream() {
|
|
|
|
@Override
|
|
|
|
public void write(int b) throws IOException {
|
|
|
|
raf.write(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(byte[] b) throws IOException {
|
|
|
|
raf.write(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(byte[] b, int off, int len) throws IOException {
|
|
|
|
raf.write(b, off, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
codedOutStream.writeInt32(OsmandOdb.OsmAndStructure.VERSION_FIELD_NUMBER, IndexConstants.BINARY_MAP_VERSION);
|
2010-10-27 12:36:07 +02:00
|
|
|
state.push(OSMAND_STRUCTURE_INIT);
|
|
|
|
}
|
2010-11-02 22:59:47 +01:00
|
|
|
|
|
|
|
public void finishWriting(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-10-27 12:36:07 +02:00
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
private void preserveInt32Size() throws IOException {
|
2010-10-28 09:52:19 +02:00
|
|
|
codedOutStream.flush();
|
2010-10-27 22:04:09 +02:00
|
|
|
stackSizes.push(raf.getFilePointer());
|
|
|
|
codedOutStream.writeFixed32NoTag(0);
|
|
|
|
}
|
|
|
|
|
2010-11-02 00:42:17 +01:00
|
|
|
private int writeInt32Size() throws IOException{
|
2010-10-28 09:52:19 +02:00
|
|
|
codedOutStream.flush();
|
2010-10-27 22:04:09 +02:00
|
|
|
long filePointer = raf.getFilePointer();
|
|
|
|
Long old = stackSizes.pop();
|
2010-10-28 09:52:19 +02:00
|
|
|
int length = (int) (filePointer - old - 4);
|
2010-10-27 22:04:09 +02:00
|
|
|
raf.seek(old);
|
|
|
|
raf.writeInt(length);
|
|
|
|
raf.seek(filePointer);
|
2010-11-02 00:42:17 +01:00
|
|
|
return length;
|
2010-10-27 22:04:09 +02:00
|
|
|
}
|
|
|
|
|
2010-10-27 12:36:07 +02:00
|
|
|
public void startWriteMapIndex() throws IOException{
|
2010-11-01 14:54:52 +01:00
|
|
|
pushState(MAP_INDEX_INIT, OSMAND_STRUCTURE_INIT);
|
2010-10-28 21:13:05 +02:00
|
|
|
codedOutStream.writeTag(OsmandOdb.OsmAndStructure.MAPINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
2010-10-27 22:04:09 +02:00
|
|
|
preserveInt32Size();
|
2010-10-27 12:36:07 +02:00
|
|
|
}
|
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
|
2010-10-27 12:36:07 +02:00
|
|
|
public void endWriteMapIndex() throws IOException{
|
2010-11-01 14:54:52 +01:00
|
|
|
popState(MAP_INDEX_INIT);
|
2010-11-02 00:42:17 +01:00
|
|
|
int len = writeInt32Size();
|
|
|
|
System.out.println("MAP INDEX SIZE : " + len);
|
2010-10-27 12:36:07 +02:00
|
|
|
}
|
|
|
|
|
2010-10-28 09:52:19 +02:00
|
|
|
public void startWriteMapLevelIndex(int minZoom, int maxZoom, int leftX, int rightX, int topY, int bottomY) throws IOException{
|
2010-11-01 14:54:52 +01:00
|
|
|
pushState(MAP_ROOT_LEVEL_INIT, MAP_INDEX_INIT);
|
2010-10-27 12:36:07 +02:00
|
|
|
|
2010-10-28 21:13:05 +02:00
|
|
|
codedOutStream.writeTag(OsmandOdb.OsmAndMapIndex.LEVELS_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
2010-10-27 22:04:09 +02:00
|
|
|
preserveInt32Size();
|
2010-10-27 12:36:07 +02:00
|
|
|
|
|
|
|
codedOutStream.writeInt32(OsmandOdb.MapRootLevel.MAXZOOM_FIELD_NUMBER, maxZoom);
|
|
|
|
codedOutStream.writeInt32(OsmandOdb.MapRootLevel.MINZOOM_FIELD_NUMBER, minZoom);
|
|
|
|
codedOutStream.writeInt32(OsmandOdb.MapRootLevel.LEFT_FIELD_NUMBER, leftX);
|
|
|
|
codedOutStream.writeInt32(OsmandOdb.MapRootLevel.RIGHT_FIELD_NUMBER, rightX);
|
|
|
|
codedOutStream.writeInt32(OsmandOdb.MapRootLevel.TOP_FIELD_NUMBER, topY);
|
|
|
|
codedOutStream.writeInt32(OsmandOdb.MapRootLevel.BOTTOM_FIELD_NUMBER, bottomY);
|
|
|
|
|
|
|
|
stackBounds.push(new Bounds(leftX, rightX, topY, bottomY));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void endWriteMapLevelIndex() throws IOException{
|
2010-11-01 14:54:52 +01:00
|
|
|
popState(MAP_ROOT_LEVEL_INIT);
|
2010-10-27 12:36:07 +02:00
|
|
|
stackBounds.pop();
|
2010-10-27 22:04:09 +02:00
|
|
|
writeInt32Size();
|
2010-10-27 12:36:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void startMapTreeElement(int leftX, int rightX, int topY, int bottomY) throws IOException{
|
2010-10-28 09:52:19 +02:00
|
|
|
startMapTreeElement(-1L, leftX, rightX, topY, bottomY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startMapTreeElement(long baseId, int leftX, int rightX, int topY, int bottomY) throws IOException{
|
2010-11-01 14:54:52 +01:00
|
|
|
checkPeekState(MAP_ROOT_LEVEL_INIT, MAP_TREE);
|
2010-10-27 12:36:07 +02:00
|
|
|
if(state.peek() == MAP_ROOT_LEVEL_INIT){
|
2010-10-28 21:13:05 +02:00
|
|
|
codedOutStream.writeTag(OsmandOdb.MapRootLevel.ROOT_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
2010-10-27 12:36:07 +02:00
|
|
|
} else {
|
2010-10-28 21:13:05 +02:00
|
|
|
codedOutStream.writeTag(OsmandOdb.MapTree.SUBTREES_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
2010-10-27 12:36:07 +02:00
|
|
|
}
|
|
|
|
state.push(MAP_TREE);
|
2010-11-01 14:54:52 +01:00
|
|
|
preserveInt32Size();
|
2010-10-27 12:36:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
Bounds bounds = stackBounds.peek();
|
|
|
|
codedOutStream.writeSInt32(OsmandOdb.MapTree.LEFT_FIELD_NUMBER, leftX - bounds.leftX);
|
|
|
|
codedOutStream.writeSInt32(OsmandOdb.MapTree.RIGHT_FIELD_NUMBER, rightX - bounds.rightX);
|
|
|
|
codedOutStream.writeSInt32(OsmandOdb.MapTree.TOP_FIELD_NUMBER, topY - bounds.topY);
|
|
|
|
codedOutStream.writeSInt32(OsmandOdb.MapTree.BOTTOM_FIELD_NUMBER, bottomY - bounds.bottomY);
|
|
|
|
stackBounds.push(new Bounds(leftX, rightX, topY, bottomY));
|
2010-10-28 09:52:19 +02:00
|
|
|
stackBaseIds.push(baseId);
|
2010-10-27 17:18:28 +02:00
|
|
|
stackStringTable.push(null);
|
2010-10-27 12:36:07 +02:00
|
|
|
}
|
|
|
|
|
2010-11-01 14:54:52 +01:00
|
|
|
|
2010-10-27 12:36:07 +02:00
|
|
|
public void endWriteMapTreeElement() throws IOException{
|
2010-11-01 14:54:52 +01:00
|
|
|
popState(MAP_TREE);
|
2010-10-27 12:36:07 +02:00
|
|
|
|
|
|
|
stackBounds.pop();
|
2010-10-27 17:18:28 +02:00
|
|
|
Long l = stackBaseIds.pop();
|
2010-10-27 22:04:09 +02:00
|
|
|
if(l != -1){
|
2010-10-27 17:18:28 +02:00
|
|
|
codedOutStream.writeTag(OsmandOdb.MapTree.BASEID_FIELD_NUMBER, WireFormat.FieldType.UINT64.getWireType());
|
|
|
|
codedOutStream.writeUInt64NoTag(l);
|
|
|
|
}
|
|
|
|
Map<String, Integer> map = stackStringTable.peek();
|
|
|
|
if(map != null){
|
|
|
|
|
|
|
|
int i = 0;
|
2010-10-27 22:04:09 +02:00
|
|
|
int size = 0;
|
2010-10-27 17:18:28 +02:00
|
|
|
for(String s : map.keySet()){
|
|
|
|
Integer integer = map.get(s);
|
|
|
|
if(integer != i){
|
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
|
|
|
i++;
|
2010-10-27 22:04:09 +02:00
|
|
|
size += CodedOutputStream.computeStringSize(OsmandOdb.StringTable.S_FIELD_NUMBER, s);
|
|
|
|
}
|
|
|
|
codedOutStream.writeTag(OsmandOdb.MapTree.STRINGTABLE_FIELD_NUMBER, WireFormat.FieldType.MESSAGE.getWireType());
|
2010-10-29 15:28:59 +02:00
|
|
|
STRING_TABLE_SIZE += CodedOutputStream.computeTagSize(OsmandOdb.MapTree.STRINGTABLE_FIELD_NUMBER) +
|
|
|
|
CodedOutputStream.computeRawVarint32Size(size) + size;
|
2010-10-27 22:04:09 +02:00
|
|
|
codedOutStream.writeRawVarint32(size);
|
|
|
|
for(String s : map.keySet()){
|
|
|
|
codedOutStream.writeString(OsmandOdb.StringTable.S_FIELD_NUMBER, s);
|
2010-10-27 17:18:28 +02:00
|
|
|
}
|
|
|
|
}
|
2010-10-27 22:04:09 +02:00
|
|
|
writeInt32Size();
|
2010-10-27 12:36:07 +02:00
|
|
|
}
|
|
|
|
|
2010-10-28 09:52:19 +02:00
|
|
|
public static int COORDINATES_SIZE = 0;
|
2010-10-30 11:06:21 +02:00
|
|
|
public static int COORDINATES_COUNT= 0;
|
2010-10-28 09:52:19 +02:00
|
|
|
public static int ID_SIZE = 0;
|
|
|
|
public static int TYPES_SIZE = 0;
|
|
|
|
public static int MAP_DATA_SIZE = 0;
|
2010-10-29 15:28:59 +02:00
|
|
|
public static int STRING_TABLE_SIZE = 0;
|
2010-10-28 09:52:19 +02:00
|
|
|
|
2010-10-30 11:06:21 +02:00
|
|
|
|
2010-10-30 11:23:51 +02:00
|
|
|
protected static int codeCoordinateDifference(int x, int px){
|
2010-10-30 20:01:05 +02:00
|
|
|
// shift absolute coordinates first and get truncated
|
2010-10-30 11:23:51 +02:00
|
|
|
return (x >> SHIFT_COORDINATES) - (px >> SHIFT_COORDINATES);
|
2010-10-30 11:06:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-27 17:18:28 +02:00
|
|
|
public void writeMapData(long id, byte[] nodes, byte[] types, String name, int highwayAttributes, byte[] restrictions) throws IOException{
|
2010-10-27 12:36:07 +02:00
|
|
|
assert state.peek() == MAP_TREE;
|
2010-10-27 17:18:28 +02:00
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
|
|
|
|
Bounds bounds = stackBounds.peek();
|
|
|
|
if(stackBaseIds.peek() == -1){
|
|
|
|
stackBaseIds.pop();
|
|
|
|
stackBaseIds.push(id);
|
2010-10-27 17:18:28 +02:00
|
|
|
}
|
2010-10-27 22:04:09 +02:00
|
|
|
// calculate size
|
|
|
|
int sizeCoordinates = 0;
|
2010-10-28 17:55:09 +02:00
|
|
|
int allSize = 0;
|
|
|
|
int px = bounds.leftX;
|
|
|
|
int py = bounds.topY;
|
2010-10-27 17:18:28 +02:00
|
|
|
for(int i=0; i< nodes.length / 8; i++){
|
2010-10-30 11:06:21 +02:00
|
|
|
int x = Algoritms.parseIntFromBytes(nodes, i * 8);
|
|
|
|
int y = Algoritms.parseIntFromBytes(nodes, i * 8 + 4);
|
2010-10-30 11:23:51 +02:00
|
|
|
sizeCoordinates += CodedOutputStream.computeSInt32SizeNoTag(codeCoordinateDifference(x, px));
|
|
|
|
sizeCoordinates += CodedOutputStream.computeSInt32SizeNoTag(codeCoordinateDifference(y, py));
|
2010-10-28 09:52:19 +02:00
|
|
|
px = x;
|
|
|
|
py = y;
|
2010-10-30 11:06:21 +02:00
|
|
|
COORDINATES_COUNT += 2;
|
2010-10-27 17:18:28 +02:00
|
|
|
}
|
2010-10-28 17:55:09 +02:00
|
|
|
allSize += CodedOutputStream.computeRawVarint32Size(sizeCoordinates) +
|
|
|
|
CodedOutputStream.computeTagSize(OsmandOdb.MapData.COORDINATES_FIELD_NUMBER) + sizeCoordinates;
|
2010-10-28 09:52:19 +02:00
|
|
|
// DEBUG
|
2010-10-28 17:55:09 +02:00
|
|
|
COORDINATES_SIZE += allSize;
|
2010-10-30 11:06:21 +02:00
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
|
2010-10-28 17:55:09 +02:00
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
allSize += CodedOutputStream.computeTagSize(OsmandOdb.MapData.TYPES_FIELD_NUMBER);
|
|
|
|
allSize += CodedOutputStream.computeRawVarint32Size(types.length);
|
|
|
|
allSize += types.length;
|
2010-10-28 09:52:19 +02:00
|
|
|
// DEBUG
|
|
|
|
TYPES_SIZE += CodedOutputStream.computeTagSize(OsmandOdb.MapData.TYPES_FIELD_NUMBER) +
|
|
|
|
CodedOutputStream.computeRawVarint32Size(types.length) + types.length;
|
2010-10-28 17:55:09 +02:00
|
|
|
|
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
allSize += CodedOutputStream.computeSInt64Size(OsmandOdb.MapData.ID_FIELD_NUMBER, id - stackBaseIds.peek());
|
2010-10-28 09:52:19 +02:00
|
|
|
// DEBUG
|
|
|
|
ID_SIZE += CodedOutputStream.computeSInt64Size(OsmandOdb.MapData.ID_FIELD_NUMBER, id - stackBaseIds.peek());
|
2010-10-27 17:18:28 +02:00
|
|
|
|
2010-10-28 17:55:09 +02:00
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
int nameId = 0;
|
2010-10-27 17:18:28 +02:00
|
|
|
if(name != null){
|
|
|
|
if(stackStringTable.peek() == null) {
|
|
|
|
stackStringTable.pop();
|
|
|
|
stackStringTable.push(new LinkedHashMap<String, Integer>());
|
|
|
|
}
|
|
|
|
Map<String, Integer> map = stackStringTable.peek();
|
|
|
|
if(map.containsKey(name)) {
|
2010-10-27 22:04:09 +02:00
|
|
|
nameId = map.get(name);
|
2010-10-27 17:18:28 +02:00
|
|
|
} else {
|
2010-10-27 22:04:09 +02:00
|
|
|
nameId = map.size();
|
|
|
|
map.put(name, nameId);
|
2010-10-27 17:18:28 +02:00
|
|
|
}
|
2010-10-27 22:04:09 +02:00
|
|
|
allSize += CodedOutputStream.computeUInt32Size(OsmandOdb.MapData.STRINGID_FIELD_NUMBER, nameId);
|
2010-10-27 17:18:28 +02:00
|
|
|
}
|
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
int restrictionsSize = 0;
|
2010-10-27 17:18:28 +02:00
|
|
|
if(restrictions.length > 0){
|
2010-10-27 22:04:09 +02:00
|
|
|
allSize += CodedOutputStream.computeTagSize(OsmandOdb.MapData.RESTRICTIONS_FIELD_NUMBER);
|
|
|
|
for (int i = 0; i < restrictions.length / 8; i++) {
|
|
|
|
long l = Algoritms.parseLongFromBytes(restrictions, i * 8) - stackBaseIds.peek();
|
|
|
|
restrictionsSize += CodedOutputStream.computeSInt64SizeNoTag(l);
|
|
|
|
}
|
|
|
|
allSize += CodedOutputStream.computeRawVarint32Size(restrictionsSize);
|
|
|
|
allSize += restrictionsSize;
|
2010-10-27 17:18:28 +02:00
|
|
|
}
|
|
|
|
if(highwayAttributes != 0){
|
2010-10-27 22:04:09 +02:00
|
|
|
allSize += CodedOutputStream.computeInt32Size(OsmandOdb.MapData.HIGHWAYMETA_FIELD_NUMBER, highwayAttributes);
|
2010-10-27 17:18:28 +02:00
|
|
|
}
|
|
|
|
|
2010-10-28 09:52:19 +02:00
|
|
|
// DEBUG
|
|
|
|
MAP_DATA_SIZE += allSize;
|
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
// writing data
|
|
|
|
codedOutStream.writeTag(OsmandOdb.MapTree.LEAFS_FIELD_NUMBER, WireFormat.FieldType.MESSAGE.getWireType());
|
|
|
|
codedOutStream.writeRawVarint32(allSize);
|
|
|
|
|
2010-10-28 17:55:09 +02:00
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
codedOutStream.writeTag(OsmandOdb.MapData.COORDINATES_FIELD_NUMBER, WireFormat.FieldType.BYTES.getWireType());
|
|
|
|
codedOutStream.writeRawVarint32(sizeCoordinates);
|
2010-10-28 09:52:19 +02:00
|
|
|
|
2010-10-30 20:01:05 +02:00
|
|
|
px = bounds.leftX;
|
2010-10-28 17:55:09 +02:00
|
|
|
py = bounds.topY;
|
2010-10-27 22:04:09 +02:00
|
|
|
for (int i = 0; i < nodes.length / 8; i++) {
|
2010-10-30 11:06:21 +02:00
|
|
|
int x = Algoritms.parseIntFromBytes(nodes, i * 8);
|
|
|
|
int y = Algoritms.parseIntFromBytes(nodes, i * 8 + 4);
|
2010-10-30 11:23:51 +02:00
|
|
|
codedOutStream.writeSInt32NoTag(codeCoordinateDifference(x, px));
|
|
|
|
codedOutStream.writeSInt32NoTag(codeCoordinateDifference(y, py));
|
2010-10-28 09:52:19 +02:00
|
|
|
px = x;
|
|
|
|
py = y;
|
2010-10-27 22:04:09 +02:00
|
|
|
}
|
|
|
|
|
2010-10-28 17:55:09 +02:00
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
codedOutStream.writeTag(OsmandOdb.MapData.TYPES_FIELD_NUMBER, WireFormat.FieldType.BYTES.getWireType());
|
|
|
|
codedOutStream.writeRawVarint32(types.length);
|
|
|
|
codedOutStream.writeRawBytes(types);
|
|
|
|
|
|
|
|
codedOutStream.writeSInt64(OsmandOdb.MapData.ID_FIELD_NUMBER, id - stackBaseIds.peek());
|
|
|
|
|
2010-10-28 17:55:09 +02:00
|
|
|
|
2010-10-27 22:04:09 +02:00
|
|
|
if(name != null){
|
|
|
|
codedOutStream.writeUInt32(OsmandOdb.MapData.STRINGID_FIELD_NUMBER, nameId);
|
2010-10-28 17:55:09 +02:00
|
|
|
}
|
2010-10-27 22:04:09 +02:00
|
|
|
|
|
|
|
if(restrictions.length > 0){
|
|
|
|
codedOutStream.writeTag(OsmandOdb.MapData.RESTRICTIONS_FIELD_NUMBER, WireFormat.FieldType.BYTES.getWireType());
|
|
|
|
codedOutStream.writeRawVarint32(restrictionsSize);
|
|
|
|
for (int i = 0; i < restrictions.length / 8; i++) {
|
|
|
|
long l = Algoritms.parseLongFromBytes(restrictions, i * 8) - stackBaseIds.peek();
|
|
|
|
codedOutStream.writeSInt64NoTag(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(highwayAttributes != 0){
|
|
|
|
codedOutStream.writeInt32(OsmandOdb.MapData.HIGHWAYMETA_FIELD_NUMBER, highwayAttributes);
|
|
|
|
}
|
2010-10-27 12:36:07 +02:00
|
|
|
}
|
2010-11-01 14:54:52 +01:00
|
|
|
|
|
|
|
public void startWriteAddressIndex(String name) throws IOException {
|
2010-11-02 00:42:17 +01:00
|
|
|
pushState(ADDRESS_INDEX_INIT, OSMAND_STRUCTURE_INIT);
|
2010-11-01 14:54:52 +01:00
|
|
|
codedOutStream.writeTag(OsmandOdb.OsmAndStructure.ADDRESSINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
|
|
|
preserveInt32Size();
|
|
|
|
|
|
|
|
codedOutStream.writeString(OsmandOdb.OsmAndAddressIndex.NAME_FIELD_NUMBER, name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void endWriteAddressIndex() throws IOException {
|
|
|
|
popState(ADDRESS_INDEX_INIT);
|
2010-11-02 00:42:17 +01:00
|
|
|
int len = writeInt32Size();
|
|
|
|
System.out.println("ADDRESS INDEX SIZE : " + len);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean checkEnNameToWrite(MapObject obj){
|
|
|
|
if(obj.getEnName() == null){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !obj.getEnName().equals(Junidecode.unidecode(obj.getName()));
|
|
|
|
}
|
|
|
|
|
2010-11-03 14:07:14 +01:00
|
|
|
public void writeCityIndex(City city, List<Street> streets, Map<Street, List<Node>> wayNodes) throws IOException {
|
2010-11-02 00:42:17 +01:00
|
|
|
if(city.getType() == City.CityType.CITY || city.getType() == City.CityType.TOWN){
|
|
|
|
checkPeekState(CITY_INDEX_INIT);
|
|
|
|
} else {
|
|
|
|
checkPeekState(VILLAGES_INDEX_INIT);
|
|
|
|
}
|
|
|
|
CityIndex.Builder cityInd = OsmandOdb.CityIndex.newBuilder();
|
|
|
|
cityInd.setCityType(city.getType().ordinal());
|
|
|
|
cityInd.setId(city.getId());
|
|
|
|
|
|
|
|
cityInd.setName(city.getName());
|
|
|
|
if(checkEnNameToWrite(city)){
|
|
|
|
cityInd.setNameEn(city.getEnName());
|
|
|
|
}
|
2010-11-03 14:07:14 +01:00
|
|
|
int cx = MapUtils.get31TileNumberX(city.getLocation().getLongitude());
|
|
|
|
int cy = MapUtils.get31TileNumberY(city.getLocation().getLatitude());
|
|
|
|
cityInd.setX(cx);
|
|
|
|
cityInd.setY(cy);
|
|
|
|
|
|
|
|
if(wayNodes != null){
|
|
|
|
InteresectedStreets.Builder sbuilders = OsmandOdb.InteresectedStreets.newBuilder();
|
2010-11-05 13:11:09 +01:00
|
|
|
Map<Long, Set<Integer>> reverseMap = new LinkedHashMap<Long, Set<Integer>>();
|
2010-11-03 14:07:14 +01:00
|
|
|
for (int i = 0; i < streets.size(); i++) {
|
2010-11-05 13:11:09 +01:00
|
|
|
streets.get(i).setIndexInCity(i);
|
|
|
|
for (Node n : wayNodes.get(streets.get(i))) {
|
|
|
|
if(!reverseMap.containsKey(n.getId())){
|
|
|
|
reverseMap.put(n.getId(), new LinkedHashSet<Integer>(3));
|
2010-11-03 14:07:14 +01:00
|
|
|
}
|
2010-11-05 13:11:09 +01:00
|
|
|
reverseMap.get(n.getId()).add(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Set<Integer> checkedStreets = new LinkedHashSet<Integer>();
|
|
|
|
for (int i = 0; i < streets.size(); i++) {
|
|
|
|
Street s1 = streets.get(i);
|
|
|
|
checkedStreets.clear();
|
|
|
|
for(Node intersection : wayNodes.get(s1)){
|
|
|
|
for(Integer j : reverseMap.get(intersection.getId())){
|
|
|
|
if(i >= j || checkedStreets.contains(j)){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
checkedStreets.add(j);
|
2010-11-03 14:07:14 +01:00
|
|
|
StreetIntersection.Builder builder = OsmandOdb.StreetIntersection.newBuilder();
|
|
|
|
builder.setIntersectedStreet1(i);
|
|
|
|
builder.setIntersectedStreet2(j);
|
|
|
|
int sx = MapUtils.get31TileNumberX(intersection.getLongitude());
|
|
|
|
int sy = MapUtils.get31TileNumberY(intersection.getLatitude());
|
|
|
|
builder.setIntersectedX((sx - cx) >> 7);
|
|
|
|
builder.setIntersectedY((sy - cy) >> 7);
|
|
|
|
sbuilders.addIntersections(builder.build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cityInd.setIntersections(sbuilders.build());
|
|
|
|
}
|
2010-11-02 00:42:17 +01:00
|
|
|
|
|
|
|
for(Street s : streets){
|
2010-11-03 14:07:14 +01:00
|
|
|
StreetIndex streetInd = createStreetAndBuildings(s, cx, cy, null);
|
2010-11-02 00:42:17 +01:00
|
|
|
cityInd.addStreets(streetInd);
|
|
|
|
}
|
|
|
|
codedOutStream.writeMessage(OsmandOdb.CitiesIndex.CITIES_FIELD_NUMBER, cityInd.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startCityIndexes(boolean villages) throws IOException {
|
|
|
|
pushState(villages ? VILLAGES_INDEX_INIT : CITY_INDEX_INIT, ADDRESS_INDEX_INIT);
|
|
|
|
codedOutStream.writeTag(villages ? OsmandOdb.OsmAndAddressIndex.VILLAGES_FIELD_NUMBER
|
|
|
|
: OsmandOdb.OsmAndAddressIndex.CITIES_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
|
|
|
preserveInt32Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void endCityIndexes(boolean villages) throws IOException {
|
|
|
|
popState(villages ? VILLAGES_INDEX_INIT : CITY_INDEX_INIT);
|
2010-11-02 00:54:41 +01:00
|
|
|
int length = writeInt32Size();
|
|
|
|
System.out.println("CITIES size " + length + " " + villages);
|
2010-11-01 14:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-02 00:42:17 +01:00
|
|
|
public void startPostcodes() throws IOException {
|
|
|
|
pushState(POSTCODES_INDEX_INIT, ADDRESS_INDEX_INIT);
|
|
|
|
codedOutStream.writeTag(OsmandOdb.OsmAndAddressIndex.POSTCODES_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
2010-11-01 14:54:52 +01:00
|
|
|
preserveInt32Size();
|
2010-11-02 00:42:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void endPostcodes() throws IOException {
|
|
|
|
popState(POSTCODES_INDEX_INIT);
|
2010-11-02 00:54:41 +01:00
|
|
|
int postcodes = writeInt32Size();
|
|
|
|
System.out.println("POSTCODES size " + postcodes);
|
2010-11-02 00:42:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-02 00:54:41 +01:00
|
|
|
public void writePostcode(String postcode, Collection<Street> streets) throws IOException {
|
2010-11-02 00:42:17 +01:00
|
|
|
checkPeekState(POSTCODES_INDEX_INIT);
|
2010-11-02 22:59:47 +01:00
|
|
|
|
|
|
|
if(streets.isEmpty()){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
postcode = postcode.toUpperCase();
|
|
|
|
LatLon loc = streets.iterator().next().getLocation();
|
2010-11-02 00:42:17 +01:00
|
|
|
PostcodeIndex.Builder post = OsmandOdb.PostcodeIndex.newBuilder();
|
|
|
|
post.setPostcode(postcode);
|
2010-11-03 14:07:14 +01:00
|
|
|
int cx = MapUtils.get31TileNumberX(loc.getLongitude());
|
|
|
|
int cy = MapUtils.get31TileNumberY(loc.getLatitude());
|
|
|
|
post.setX(cx);
|
|
|
|
post.setY(cy);
|
2010-11-02 00:42:17 +01:00
|
|
|
|
|
|
|
for(Street s : streets){
|
2010-11-03 14:07:14 +01:00
|
|
|
StreetIndex streetInd = createStreetAndBuildings(s, cx, cy, postcode);
|
2010-11-02 00:42:17 +01:00
|
|
|
post.addStreets(streetInd);
|
2010-11-01 14:54:52 +01:00
|
|
|
}
|
2010-11-02 00:42:17 +01:00
|
|
|
codedOutStream.writeMessage(OsmandOdb.PostcodesIndex.POSTCODES_FIELD_NUMBER, post.build());
|
2010-11-01 14:54:52 +01:00
|
|
|
}
|
|
|
|
|
2010-11-02 00:42:17 +01:00
|
|
|
|
2010-11-03 14:07:14 +01:00
|
|
|
protected StreetIndex createStreetAndBuildings(Street street, int cx, int cy, String postcodeFilter) throws IOException {
|
2010-11-02 11:41:53 +01:00
|
|
|
checkPeekState(CITY_INDEX_INIT, VILLAGES_INDEX_INIT, POSTCODES_INDEX_INIT);
|
|
|
|
boolean inCity = state.peek() == CITY_INDEX_INIT || state.peek() == VILLAGES_INDEX_INIT;
|
2010-11-01 14:54:52 +01:00
|
|
|
StreetIndex.Builder streetBuilder = OsmandOdb.StreetIndex.newBuilder();
|
|
|
|
streetBuilder.setName(street.getName());
|
2010-11-02 00:42:17 +01:00
|
|
|
if(checkEnNameToWrite(street)){
|
2010-11-01 14:54:52 +01:00
|
|
|
streetBuilder.setNameEn(street.getEnName());
|
|
|
|
}
|
|
|
|
streetBuilder.setId(street.getId());
|
|
|
|
|
|
|
|
|
|
|
|
int sx = MapUtils.get31TileNumberX(street.getLocation().getLongitude());
|
|
|
|
int sy = MapUtils.get31TileNumberY(street.getLocation().getLatitude());
|
|
|
|
streetBuilder.setX((sx - cx) >> 7);
|
|
|
|
streetBuilder.setY((sy - cy) >> 7);
|
|
|
|
|
|
|
|
for(Building b : street.getBuildings()){
|
2010-11-02 00:42:17 +01:00
|
|
|
if(postcodeFilter != null && !postcodeFilter.equalsIgnoreCase(b.getPostcode())){
|
|
|
|
continue;
|
|
|
|
}
|
2010-11-01 14:54:52 +01:00
|
|
|
OsmandOdb.BuildingIndex.Builder bbuilder= OsmandOdb.BuildingIndex.newBuilder();
|
|
|
|
int bx = MapUtils.get31TileNumberX(b.getLocation().getLongitude());
|
|
|
|
int by = MapUtils.get31TileNumberY(b.getLocation().getLatitude());
|
|
|
|
bbuilder.setX((bx - sx) >> 7);
|
|
|
|
bbuilder.setY((by - sy) >> 7);
|
|
|
|
bbuilder.setId(b.getId());
|
|
|
|
bbuilder.setName(b.getName());
|
2010-11-02 00:42:17 +01:00
|
|
|
if(checkEnNameToWrite(b)){
|
2010-11-01 14:54:52 +01:00
|
|
|
bbuilder.setNameEn(b.getEnName());
|
|
|
|
}
|
2010-11-02 00:42:17 +01:00
|
|
|
if(inCity && b.getPostcode() != null){
|
|
|
|
bbuilder.setPostcode(b.getPostcode());
|
|
|
|
}
|
2010-11-01 14:54:52 +01:00
|
|
|
streetBuilder.addBuildings(bbuilder.build());
|
|
|
|
}
|
|
|
|
|
2010-11-02 00:42:17 +01:00
|
|
|
return streetBuilder.build();
|
2010-11-01 14:54:52 +01:00
|
|
|
}
|
|
|
|
|
2010-11-05 13:11:09 +01:00
|
|
|
public void startWriteTransportIndex() throws IOException {
|
|
|
|
pushState(TRANSPORT_INDEX_INIT, OSMAND_STRUCTURE_INIT);
|
|
|
|
codedOutStream.writeTag(OsmandOdb.OsmAndStructure.TRANSPORTINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
|
|
|
stackBounds.push(new Bounds(0, 0, 0, 0)); // for transport stops tree
|
|
|
|
preserveInt32Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void endWriteTransportIndex() throws IOException {
|
|
|
|
popState(TRANSPORT_INDEX_INIT);
|
|
|
|
int len = writeInt32Size();
|
|
|
|
stackBounds.pop();
|
|
|
|
System.out.println("TRANSPORT INDEX SIZE : " + len);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int registerString(Map<String, Integer> stringTable, String s) {
|
|
|
|
if (stringTable.containsKey(s)) {
|
|
|
|
return stringTable.get(s);
|
|
|
|
}
|
|
|
|
int size = stringTable.size();
|
|
|
|
stringTable.put(s, size);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeTransportRoute(long idRoute, String routeName, String routeEnName, String ref, String operator, String type,
|
|
|
|
int dist, List<TransportStop> directStops, List<TransportStop> reverseStops, Map<String, Integer> stringTable) throws IOException {
|
|
|
|
checkPeekState(TRANSPORT_INDEX_INIT);
|
|
|
|
TransportRoute.Builder tRoute = OsmandOdb.TransportRoute.newBuilder();
|
|
|
|
tRoute.setRef(ref);
|
|
|
|
tRoute.setOperator(registerString(stringTable, operator));
|
|
|
|
tRoute.setType(registerString(stringTable, type));
|
|
|
|
tRoute.setId(idRoute);
|
|
|
|
tRoute.setName(registerString(stringTable, routeName));
|
|
|
|
tRoute.setDistance(dist);
|
|
|
|
|
|
|
|
if(routeEnName != null){
|
|
|
|
tRoute.setNameEn(registerString(stringTable, routeEnName));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
List<TransportStop> stops = i == 0 ? directStops : reverseStops;
|
|
|
|
long id = 0;
|
|
|
|
int x24 = 0;
|
|
|
|
int y24 = 0;
|
|
|
|
for (TransportStop st : stops) {
|
|
|
|
TransportRouteStop.Builder tStop = OsmandOdb.TransportRouteStop.newBuilder();
|
|
|
|
tStop.setId(st.getId() - id);
|
|
|
|
id = st.getId();
|
|
|
|
int x = (int) MapUtils.getTileNumberX(24, st.getLocation().getLongitude());
|
|
|
|
int y = (int) MapUtils.getTileNumberY(24, st.getLocation().getLatitude());
|
|
|
|
tStop.setDx(x - x24);
|
|
|
|
tStop.setDy(y - y24);
|
|
|
|
x24 = x;
|
|
|
|
y24 = y;
|
|
|
|
tStop.setName(registerString(stringTable, st.getName()));
|
|
|
|
if (st.getEnName() != null) {
|
|
|
|
tStop.setNameEn(registerString(stringTable, st.getEnName()));
|
|
|
|
}
|
|
|
|
if (i == 0) {
|
|
|
|
tRoute.addDirectStops(tStop.build());
|
|
|
|
} else {
|
|
|
|
tRoute.addReverseStops(tStop.build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
codedOutStream.writeMessage(OsmandOdb.OsmAndTransportIndex.ROUTES_FIELD_NUMBER, tRoute.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startTransportTreeElement(int leftX, int rightX, int topY, int bottomY) throws IOException {
|
|
|
|
checkPeekState(TRANSPORT_STOPS_TREE, TRANSPORT_INDEX_INIT);
|
|
|
|
if(state.peek() == TRANSPORT_STOPS_TREE){
|
|
|
|
codedOutStream.writeTag(OsmandOdb.TransportStopsTree.SUBTREES_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
|
|
|
} else {
|
|
|
|
codedOutStream.writeTag(OsmandOdb.OsmAndTransportIndex.STOPS_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
|
|
|
}
|
|
|
|
state.push(TRANSPORT_STOPS_TREE);
|
|
|
|
preserveInt32Size();
|
|
|
|
|
|
|
|
|
|
|
|
Bounds bounds = stackBounds.peek();
|
|
|
|
|
|
|
|
codedOutStream.writeSInt32(OsmandOdb.TransportStopsTree.LEFT_FIELD_NUMBER, leftX - bounds.leftX);
|
|
|
|
codedOutStream.writeSInt32(OsmandOdb.TransportStopsTree.RIGHT_FIELD_NUMBER, rightX - bounds.rightX);
|
|
|
|
codedOutStream.writeSInt32(OsmandOdb.TransportStopsTree.TOP_FIELD_NUMBER, topY - bounds.topY);
|
|
|
|
codedOutStream.writeSInt32(OsmandOdb.TransportStopsTree.BOTTOM_FIELD_NUMBER, bottomY - bounds.bottomY);
|
|
|
|
stackBounds.push(new Bounds(leftX, rightX, topY, bottomY));
|
|
|
|
stackBaseIds.push(-1L);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void endWriteTransportTreeElement() throws IOException {
|
|
|
|
Long baseId = stackBaseIds.pop();
|
|
|
|
if(baseId >= 0){
|
|
|
|
codedOutStream.writeUInt64(OsmandOdb.TransportStopsTree.BASEID_FIELD_NUMBER, baseId);
|
|
|
|
}
|
|
|
|
popState(TRANSPORT_STOPS_TREE);
|
|
|
|
stackBounds.pop();
|
|
|
|
writeInt32Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void writeTransportStringTable(Map<String, Integer> stringTable) throws IOException {
|
|
|
|
checkPeekState(TRANSPORT_INDEX_INIT);
|
|
|
|
// expect linked hash map
|
|
|
|
int i = 0;
|
|
|
|
OsmandOdb.StringTable.Builder st = OsmandOdb.StringTable.newBuilder();
|
|
|
|
for(String s : stringTable.keySet()){
|
|
|
|
if(stringTable.get(s) != i++){
|
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
|
|
|
st.addS(s);
|
|
|
|
}
|
|
|
|
codedOutStream.writeMessage(OsmAndTransportIndex.STRINGTABLE_FIELD_NUMBER, st.build());
|
|
|
|
}
|
|
|
|
|
2010-10-27 17:18:28 +02:00
|
|
|
|
2010-11-01 14:54:52 +01:00
|
|
|
private void pushState(int push, int peek){
|
|
|
|
if(state.peek() != peek){
|
|
|
|
throw new IllegalStateException("expected " + peek+ " != "+ state.peek());
|
|
|
|
}
|
|
|
|
state.push(push);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkPeekState(int... states) {
|
2010-11-02 22:59:47 +01:00
|
|
|
for (int i = 0; i < states.length; i++) {
|
|
|
|
if (states[i] == state.peek()) {
|
2010-11-01 14:54:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new IllegalStateException("Note expected state : " + state.peek());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void popState(int state){
|
|
|
|
Integer st = this.state.pop();
|
|
|
|
if(st != state){
|
|
|
|
throw new IllegalStateException("expected " + state + " != "+ st);
|
|
|
|
}
|
|
|
|
}
|
2010-10-27 12:36:07 +02:00
|
|
|
|
|
|
|
public void close() throws IOException{
|
2010-11-02 22:59:47 +01:00
|
|
|
checkPeekState(OSMAND_STRUCTURE_INIT);
|
|
|
|
codedOutStream.writeInt32(OsmandOdb.OsmAndStructure.VERSIONCONFIRM_FIELD_NUMBER, IndexConstants.BINARY_MAP_VERSION);
|
2010-10-27 12:36:07 +02:00
|
|
|
codedOutStream.flush();
|
|
|
|
}
|
2010-11-05 13:11:09 +01:00
|
|
|
|
|
|
|
|
2010-10-27 12:36:07 +02:00
|
|
|
}
|