diff --git a/Maploader/World/SubChunkData.cs b/Maploader/World/SubChunkData.cs index c354776..34a4fa8 100644 --- a/Maploader/World/SubChunkData.cs +++ b/Maploader/World/SubChunkData.cs @@ -7,6 +7,7 @@ public class SubChunkData { public byte[] Key { get; set; } public byte[] Data { get; set; } + public int DataLength { get; set; } public UInt32 Crc32 { get; set; } public byte Index { get; set; } public bool FoundInDb { get; set; } diff --git a/Maploader/World/World.cs b/Maploader/World/World.cs index 7bd6042..23b3d91 100644 --- a/Maploader/World/World.cs +++ b/Maploader/World/World.cs @@ -79,16 +79,17 @@ public ChunkData GetOverworldChunkData(int x, int z) for (byte subChunkIdx = 0; subChunkIdx < 15; subChunkIdx++) { key[9] = subChunkIdx; - - var data = db.Get(key); + UIntPtr length; + var data = db.Get(key, out length); if (data != null) { var subChunkData = new SubChunkData() { Index = subChunkIdx, Data = data, + DataLength = (int)length, Key = key, - Crc32 = Force.Crc32.Crc32CAlgorithm.Compute(data) + Crc32 = Force.Crc32.Crc32CAlgorithm.Compute(data, 0, (int)length) }; ret.SubChunks.Add(subChunkData); } @@ -132,8 +133,8 @@ public Chunk GetChunk(int x, int z) for (byte subChunkIdx = 0; subChunkIdx < 15; subChunkIdx++) { key[9] = subChunkIdx; - - var data = db.Get(key); + UIntPtr length; + var data = db.Get(key, out length); if (data != null) { subChunks[subChunkIdx] = data; @@ -493,16 +494,17 @@ public ChunkData GetChunkData(GroupedChunkSubKeys groupedChunkSubKeys) foreach (var kvp in groupedChunkSubKeys.Subchunks) { var key = kvp.Value; - - var data = db.Get(key.Key); + UIntPtr length; + var data = db.Get(key.Key, out length); if (data != null) { var subChunkData = new SubChunkData() { Index = kvp.Key, Data = data, + DataLength = (int)length, Key = kvp.Value.Key, - Crc32 = Force.Crc32.Crc32CAlgorithm.Compute(data), + Crc32 = Force.Crc32.Crc32CAlgorithm.Compute(data, 0, (int)length), }; ret.SubChunks.Add(subChunkData); } @@ -531,16 +533,17 @@ public ChunkData GetChunkData(IGrouping groupedChunkSub foreach (var kvp in groupedChunkSubKeys) { var key = kvp; - - var data = db.Get(key.Key); + UIntPtr length; + var data = db.Get(key.Key, out length); if (data != null) { var subChunkData = new SubChunkData() { Index = key.SubChunkId, Data = data, + DataLength = (int)length, Key = key.Key, - // Crc32 = Force.Crc32.Crc32CAlgorithm.Compute(data), + // Crc32 = Force.Crc32.Crc32CAlgorithm.Compute(data, 0, (int)length), }; ret.SubChunks.Add(subChunkData); } @@ -566,15 +569,17 @@ public ChunkData GetChunkData(int x, int z) var key = CreateKey(x, z); key[9] = (byte)kvp; - var data = db.Get(key); + UIntPtr length; + var data = db.Get(key, out length); if (data != null) { var subChunkData = new SubChunkData() { Index = (byte)kvp, Data = data, + DataLength = (int)length, Key = key, - Crc32 = Force.Crc32.Crc32CAlgorithm.Compute(data), + Crc32 = Force.Crc32.Crc32CAlgorithm.Compute(data, 0, (int)length), }; ret.SubChunks.Add(subChunkData); } diff --git a/leveldb-sharp-std/DB.cs b/leveldb-sharp-std/DB.cs index 56f25a6..1365644 100644 --- a/leveldb-sharp-std/DB.cs +++ b/leveldb-sharp-std/DB.cs @@ -62,7 +62,8 @@ public class DB : IDisposable, IEnumerable> public byte[] this[byte[] key] { get { - return Get(null, key); + UIntPtr unusedLength; + return Get(null, key, out unusedLength); } set { Put(null, key, value); @@ -183,18 +184,18 @@ public void Write(WriteBatch writeBatch) Write(null, writeBatch); } - public byte[] Get(ReadOptions options, byte[] key) + public byte[] Get(ReadOptions options, byte[] key, out UIntPtr length) { CheckDisposed(); if (options == null) { options = new ReadOptions(); } - return Native.leveldb_get(Handle, options.Handle, key); + return Native.leveldb_get(Handle, options.Handle, key, out length); } - public byte[] Get(byte[] key) + public byte[] Get(byte[] key, out UIntPtr length) { - return Get(null, key); + return Get(null, key, out length); } IEnumerator IEnumerable.GetEnumerator() diff --git a/leveldb-sharp-std/Native.cs b/leveldb-sharp-std/Native.cs index aba1e7b..27d4022 100644 --- a/leveldb-sharp-std/Native.cs +++ b/leveldb-sharp-std/Native.cs @@ -196,7 +196,8 @@ public static extern IntPtr leveldb_get(IntPtr db, public static byte[] leveldb_get(IntPtr db, IntPtr readOptions, - byte[] key) + byte[] key, + out UIntPtr valueLength) { @@ -204,7 +205,6 @@ public static byte[] leveldb_get(IntPtr db, { fixed (byte* p = key) { - UIntPtr valueLength; string error; var keyLength = (UIntPtr) key.Length; IntPtr keyPtr = (IntPtr)p;