corrected lazy crc logic
This commit is contained in:
parent
e4c11e6dbf
commit
0a6ead24a1
5 changed files with 24 additions and 23 deletions
|
@ -34,15 +34,13 @@ public final class MicroCache2 extends MicroCache
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MicroCache2( DataBuffers dataBuffers, int lonIdx, int latIdx, int divisor, TagValueValidator wayValidator, WaypointMatcher waypointMatcher ) throws Exception
|
public MicroCache2( StatCoderContext bc, DataBuffers dataBuffers, int lonIdx, int latIdx, int divisor, TagValueValidator wayValidator, WaypointMatcher waypointMatcher ) throws Exception
|
||||||
{
|
{
|
||||||
super( null );
|
super( null );
|
||||||
cellsize = 1000000 / divisor;
|
cellsize = 1000000 / divisor;
|
||||||
lonBase = lonIdx*cellsize;
|
lonBase = lonIdx*cellsize;
|
||||||
latBase = latIdx*cellsize;
|
latBase = latIdx*cellsize;
|
||||||
|
|
||||||
StatCoderContext bc = new StatCoderContext( dataBuffers.iobuffer );
|
|
||||||
|
|
||||||
TagValueCoder wayTagCoder = new TagValueCoder( bc, dataBuffers, wayValidator );
|
TagValueCoder wayTagCoder = new TagValueCoder( bc, dataBuffers, wayValidator );
|
||||||
TagValueCoder nodeTagCoder = new TagValueCoder( bc, dataBuffers, null );
|
TagValueCoder nodeTagCoder = new TagValueCoder( bc, dataBuffers, null );
|
||||||
NoisyDiffCoder nodeIdxDiff = new NoisyDiffCoder( bc );
|
NoisyDiffCoder nodeIdxDiff = new NoisyDiffCoder( bc );
|
||||||
|
|
|
@ -433,7 +433,7 @@ public class WayLinker extends MapCreatorBase
|
||||||
System.arraycopy( abBuf1, 0, subBytes, 0, len );
|
System.arraycopy( abBuf1, 0, subBytes, 0, len );
|
||||||
|
|
||||||
// cross-check the encoding: re-instantiate the cache
|
// cross-check the encoding: re-instantiate the cache
|
||||||
MicroCache mc2 = new MicroCache2( new DataBuffers( subBytes ), lonIdxDiv, latIdxDiv, divisor, null, null );
|
MicroCache mc2 = new MicroCache2( new StatCoderContext( subBytes ), new DataBuffers( null ), lonIdxDiv, latIdxDiv, divisor, null, null );
|
||||||
// ..and check if still the same
|
// ..and check if still the same
|
||||||
String diffMessage = mc.compareWith( mc2 );
|
String diffMessage = mc.compareWith( mc2 );
|
||||||
if ( diffMessage != null )
|
if ( diffMessage != null )
|
||||||
|
|
|
@ -20,14 +20,12 @@ public final class DirectWeaver extends ByteDataWriter
|
||||||
|
|
||||||
private int size = 0;
|
private int size = 0;
|
||||||
|
|
||||||
public DirectWeaver( DataBuffers dataBuffers, int lonIdx, int latIdx, int divisor, TagValueValidator wayValidator, WaypointMatcher waypointMatcher, OsmNodesMap hollowNodes ) throws Exception
|
public DirectWeaver( StatCoderContext bc, DataBuffers dataBuffers, int lonIdx, int latIdx, int divisor, TagValueValidator wayValidator, WaypointMatcher waypointMatcher, OsmNodesMap hollowNodes ) throws Exception
|
||||||
{
|
{
|
||||||
super( null );
|
super( null );
|
||||||
int cellsize = 1000000 / divisor;
|
int cellsize = 1000000 / divisor;
|
||||||
id64Base = ((long)(lonIdx*cellsize))<<32 | (latIdx*cellsize);
|
id64Base = ((long)(lonIdx*cellsize))<<32 | (latIdx*cellsize);
|
||||||
|
|
||||||
StatCoderContext bc = new StatCoderContext( dataBuffers.iobuffer );
|
|
||||||
|
|
||||||
TagValueCoder wayTagCoder = new TagValueCoder( bc, dataBuffers, wayValidator );
|
TagValueCoder wayTagCoder = new TagValueCoder( bc, dataBuffers, wayValidator );
|
||||||
TagValueCoder nodeTagCoder = new TagValueCoder( bc, dataBuffers, null );
|
TagValueCoder nodeTagCoder = new TagValueCoder( bc, dataBuffers, null );
|
||||||
NoisyDiffCoder nodeIdxDiff = new NoisyDiffCoder( bc );
|
NoisyDiffCoder nodeIdxDiff = new NoisyDiffCoder( bc );
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.io.RandomAccessFile;
|
||||||
import btools.codec.DataBuffers;
|
import btools.codec.DataBuffers;
|
||||||
import btools.codec.MicroCache;
|
import btools.codec.MicroCache;
|
||||||
import btools.codec.MicroCache2;
|
import btools.codec.MicroCache2;
|
||||||
|
import btools.codec.StatCoderContext;
|
||||||
import btools.codec.TagValueValidator;
|
import btools.codec.TagValueValidator;
|
||||||
import btools.codec.WaypointMatcher;
|
import btools.codec.WaypointMatcher;
|
||||||
import btools.util.ByteDataReader;
|
import btools.util.ByteDataReader;
|
||||||
|
@ -142,9 +143,10 @@ final class OsmFile
|
||||||
{
|
{
|
||||||
ab = new byte[asize];
|
ab = new byte[asize];
|
||||||
asize = getDataInputForSubIdx( subIdx, ab );
|
asize = getDataInputForSubIdx( subIdx, ab );
|
||||||
dataBuffers = new DataBuffers( ab );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StatCoderContext bc = new StatCoderContext( ab );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if ( !reallyDecode )
|
if ( !reallyDecode )
|
||||||
|
@ -153,25 +155,28 @@ final class OsmFile
|
||||||
}
|
}
|
||||||
if ( hollowNodes == null )
|
if ( hollowNodes == null )
|
||||||
{
|
{
|
||||||
return new MicroCache2( dataBuffers, lonIdx, latIdx, divisor, wayValidator, waypointMatcher );
|
return new MicroCache2( bc, dataBuffers, lonIdx, latIdx, divisor, wayValidator, waypointMatcher );
|
||||||
}
|
}
|
||||||
new DirectWeaver( dataBuffers, lonIdx, latIdx, divisor, wayValidator, waypointMatcher, hollowNodes );
|
new DirectWeaver( bc, dataBuffers, lonIdx, latIdx, divisor, wayValidator, waypointMatcher, hollowNodes );
|
||||||
return MicroCache.emptyNonVirgin;
|
return MicroCache.emptyNonVirgin;
|
||||||
}
|
}
|
||||||
catch( Throwable t )
|
finally
|
||||||
|
{
|
||||||
|
// crc check only if the buffer has not been fully read
|
||||||
|
int readBytes = (bc.getReadingBitPosition()+7)>>3;
|
||||||
|
if ( readBytes != asize-4 )
|
||||||
{
|
{
|
||||||
// checksum test now only in case of trouble
|
|
||||||
int crcData = Crc32.crc( ab, 0, asize - 4 );
|
int crcData = Crc32.crc( ab, 0, asize - 4 );
|
||||||
int crcFooter = new ByteDataReader( ab, asize - 4 ).readInt();
|
int crcFooter = new ByteDataReader( ab, asize - 4 ).readInt();
|
||||||
if ( crcData == crcFooter )
|
if ( crcData == crcFooter )
|
||||||
{
|
{
|
||||||
throw new IOException( "old, unsupported data-format" );
|
throw new IOException( "old, unsupported data-format" );
|
||||||
}
|
}
|
||||||
else if ( ( crcData ^ 2 ) == crcFooter )
|
else if ( ( crcData ^ 2 ) != crcFooter )
|
||||||
{
|
{
|
||||||
throw new IOException( "checkum error" );
|
throw new IOException( "checkum error" );
|
||||||
}
|
}
|
||||||
throw t instanceof Exception ? (Exception)t : new Exception( t.toString(), t );
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -287,9 +287,9 @@ public class BitCoderContext
|
||||||
{
|
{
|
||||||
while (bits < 24)
|
while (bits < 24)
|
||||||
{
|
{
|
||||||
if ( idx < idxMax )
|
if ( idx++ < idxMax )
|
||||||
{
|
{
|
||||||
b |= (ab[++idx] & 0xff) << bits;
|
b |= (ab[idx] & 0xff) << bits;
|
||||||
}
|
}
|
||||||
bits += 8;
|
bits += 8;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue