variable length tag descriptions (downwards compatibility)
This commit is contained in:
parent
c16c242a65
commit
afa498637a
14 changed files with 195 additions and 58 deletions
|
|
@ -22,7 +22,7 @@ final class MicroCache
|
|||
// the object parsing position and length
|
||||
private byte[] ab;
|
||||
private int aboffset;
|
||||
private int ablength;
|
||||
private int aboffsetEnd;
|
||||
|
||||
// cache control: a virgin cache can be
|
||||
// put to ghost state for later recovery
|
||||
|
|
@ -150,7 +150,8 @@ final class MicroCache
|
|||
if ( ( fapos[n] & 0x80000000 ) == 0 )
|
||||
{
|
||||
aboffset = fapos[n];
|
||||
ablength = ( n+1 < size ? fapos[n+1] & 0x7fffffff : ab.length ) - aboffset;
|
||||
int ablength = ( n+1 < size ? fapos[n+1] & 0x7fffffff : ab.length ) - aboffset;
|
||||
aboffsetEnd = aboffset + ablength;
|
||||
fapos[n] |= 0x80000000; // mark deleted
|
||||
delbytes+= ablength;
|
||||
delcount++;
|
||||
|
|
@ -172,7 +173,7 @@ final class MicroCache
|
|||
long id = node.getIdFromPos();
|
||||
if ( getAndClear( id ) )
|
||||
{
|
||||
node.parseNodeBody( this, ablength, nodesMap, dc );
|
||||
node.parseNodeBody( this, nodesMap, dc );
|
||||
}
|
||||
|
||||
if ( doCollect && delcount > size / 2 ) // garbage collection
|
||||
|
|
@ -206,7 +207,7 @@ final class MicroCache
|
|||
int pos = fapos[i];
|
||||
if ( ( pos & 0x80000000 ) == 0 )
|
||||
{
|
||||
ablength = ( i+1 < size ? fapos[i+1] & 0x7fffffff : ab.length ) - pos;
|
||||
int ablength = ( i+1 < size ? fapos[i+1] & 0x7fffffff : ab.length ) - pos;
|
||||
System.arraycopy( ab, pos, nab, nab_off, ablength );
|
||||
nfaid[idx] = faid[i];
|
||||
nfapos[idx] = nab_off;
|
||||
|
|
@ -297,4 +298,9 @@ final class MicroCache
|
|||
System.arraycopy( ab, aboffset, ta, 0, ta.length );
|
||||
aboffset += ta.length;
|
||||
}
|
||||
|
||||
public boolean hasMoreData()
|
||||
{
|
||||
return aboffset < aboffsetEnd;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,11 @@
|
|||
*/
|
||||
package btools.mapaccess;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public final class NodesCache
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@
|
|||
*/
|
||||
package btools.mapaccess;
|
||||
|
||||
import btools.util.ByteArrayUnifier;
|
||||
|
||||
|
||||
|
||||
public class OsmNode implements OsmPos
|
||||
{
|
||||
public static final int EXTERNAL_BITMASK = 0x80;
|
||||
public static final int FIRSTFORWAY_BITMASK = 0x40;
|
||||
public static final int VARIABLEDESC_BITMASK = 0x40;
|
||||
public static final int TRANSFERNODE_BITMASK = 0x20;
|
||||
public static final int WRITEDESC_BITMASK = 0x10;
|
||||
public static final int SKIPDETAILS_BITMASK = 0x08;
|
||||
|
|
@ -107,17 +109,18 @@ public class OsmNode implements OsmPos
|
|||
}
|
||||
|
||||
|
||||
public void parseNodeBody( MicroCache is, int bodySize, OsmNodesMap hollowNodes, DistanceChecker dc )
|
||||
public void parseNodeBody( MicroCache is, OsmNodesMap hollowNodes, DistanceChecker dc )
|
||||
{
|
||||
selev = is.readShort();
|
||||
bodySize -= 2;
|
||||
ByteArrayUnifier abUnifier = hollowNodes.getByteArrayUnifier();
|
||||
|
||||
selev = is.readShort();
|
||||
|
||||
OsmLink lastlink = null;
|
||||
|
||||
int lonIdx = ilon/62500;
|
||||
int latIdx = ilat/62500;
|
||||
|
||||
while( bodySize > 0 )
|
||||
while( is.hasMoreData() )
|
||||
{
|
||||
OsmLink link = new OsmLink();
|
||||
OsmTransferNode firstTransferNode = null;
|
||||
|
|
@ -128,32 +131,33 @@ public class OsmNode implements OsmPos
|
|||
for(;;)
|
||||
{
|
||||
int bitField = is.readByte();
|
||||
bodySize -= 1;
|
||||
if ( (bitField & EXTERNAL_BITMASK) != 0 )
|
||||
{
|
||||
// full position for external target
|
||||
bodySize -= 8;
|
||||
linklon = is.readInt();
|
||||
linklat = is.readInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
// reduced position for internal target
|
||||
bodySize -= 4;
|
||||
linklon = is.readShort();
|
||||
linklat = is.readShort();
|
||||
linklon += lonIdx*62500 + 31250;
|
||||
linklat += latIdx*62500 + 31250;
|
||||
}
|
||||
// read variable length or old 8 byte fixed, and ensure that 8 bytes is only fixed
|
||||
boolean readFix8 = (bitField & VARIABLEDESC_BITMASK ) == 0; // old, fix length format
|
||||
if ( (bitField & WRITEDESC_BITMASK ) != 0 )
|
||||
{
|
||||
int dlen = is.readByte(); description = new byte[dlen]; is.readFully( description );
|
||||
bodySize -= 1 + dlen;
|
||||
byte[] ab = new byte[readFix8 ? 8 : is.readByte()];
|
||||
is.readFully( ab );
|
||||
description = abUnifier.unify( ab );
|
||||
}
|
||||
if ( (bitField & NODEDESC_BITMASK ) != 0 )
|
||||
{
|
||||
int dlen = is.readByte(); nodeDescription = new byte[dlen]; is.readFully( nodeDescription );
|
||||
bodySize -= 1 + dlen;
|
||||
byte[] ab = new byte[readFix8 ? 8 : is.readByte()];
|
||||
is.readFully( ab );
|
||||
nodeDescription = abUnifier.unify( ab );
|
||||
}
|
||||
if ( (bitField & SKIPDETAILS_BITMASK ) != 0 )
|
||||
{
|
||||
|
|
@ -169,7 +173,6 @@ public class OsmNode implements OsmPos
|
|||
trans.ilon = linklon;
|
||||
trans.ilat = linklat;
|
||||
trans.descriptionBitmap = description;
|
||||
bodySize -= 2;
|
||||
trans.selev = is.readShort();
|
||||
if ( lastTransferNode == null )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,10 +7,19 @@ package btools.mapaccess;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import btools.util.ByteArrayUnifier;
|
||||
|
||||
public final class OsmNodesMap
|
||||
{
|
||||
private HashMap<Long,OsmNode> hmap = new HashMap<Long,OsmNode>();
|
||||
|
||||
private ByteArrayUnifier abUnifier = new ByteArrayUnifier( 16384 );
|
||||
|
||||
public ByteArrayUnifier getByteArrayUnifier()
|
||||
{
|
||||
return abUnifier;
|
||||
}
|
||||
|
||||
private NodesList completedNodes = null;
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue