public Storable decode(StorableKey key,
final byte[] raw, final int offset, final int length)
{
// as per Javadocs, offset always 0, size same as arrays:
BytesToStuff reader = new BytesToStuff(raw, offset, length);
/*
for (int i = 0, end = Math.min(length, 24); i < end; ++i) {
System.out.println("#"+i+" -> 0x"+Integer.toHexString(raw[offset+i] & 0xFF));
}
*/
final long lastmod = reader.nextLong();
// Ok: ensure version number is valid
_verifyVersion(reader.nextByte());
int statusFlags = reader.nextByte();
final Compression compression = _decodeCompression(reader.nextByte());
final int externalPathLength = reader.nextByte() & 0xFF;
final int contentHash = reader.nextInt();
final long originalLength;
final int compressedHash;
// and now get to variable parts
if (compression != Compression.NONE) {
compressedHash = reader.nextInt();
long l = reader.nextVLong();
// one work-around: can't use negative values so '0' means N/A
if (l == 0L) {
l = -1L;
}
originalLength = l;
} else {
compressedHash = 0;
originalLength = -1;
}
final int metadataLength = reader.nextVInt();
final int metadataOffset = reader.offset();
reader.skip(metadataLength);
final long storageLength = reader.nextVLong();
final int payloadOffset = reader.offset();
// and one more branch: inlined or external storage?
if (externalPathLength > 0) { // external; should only have ext path in there
reader.skip(externalPathLength);
} else { // inline, should have data there
reader.skip((int) storageLength);
}
// and finally, should all add up...
int left = reader.left();
if (left > 0) {
throw new IllegalArgumentException("Had "+left+" bytes left after decoding entry (out of "
+raw.length+")");
}
return new Storable(key, ByteContainer.simple(raw, offset, length),