SkipHeader() static private method

static private SkipHeader ( AbstractBufferedReader reader ) : void
reader BTDB.StreamLayer.AbstractBufferedReader
return void
Beispiel #1
0
 bool LoadKeyIndex(uint fileId, IKeyIndex info)
 {
     try
     {
         var reader = FileCollection.GetFile(fileId).GetExclusiveReader();
         FileKeyIndex.SkipHeader(reader);
         var keyCount = info.KeyValueCount;
         _nextRoot.TrLogFileId = info.TrLogFileId;
         _nextRoot.TrLogOffset = info.TrLogOffset;
         _nextRoot.CommitUlong = info.CommitUlong;
         if (info.Compression == KeyIndexCompression.Old)
         {
             _nextRoot.BuildTree(keyCount, () =>
             {
                 var keyLength = reader.ReadVInt32();
                 var key       = ByteBuffer.NewAsync(new byte[Math.Abs(keyLength)]);
                 reader.ReadBlock(key);
                 if (keyLength < 0)
                 {
                     _compression.DecompressKey(ref key);
                 }
                 return(new BTreeLeafMember
                 {
                     Key = key.ToByteArray(),
                     ValueFileId = reader.ReadVUInt32(),
                     ValueOfs = reader.ReadVUInt32(),
                     ValueSize = reader.ReadVInt32()
                 });
             });
         }
         else
         {
             if (info.Compression != KeyIndexCompression.None)
             {
                 return(false);
             }
             var prevKey = ByteBuffer.NewEmpty();
             _nextRoot.BuildTree(keyCount, () =>
             {
                 var prefixLen = (int)reader.ReadVUInt32();
                 var keyLengthWithoutPrefix = (int)reader.ReadVUInt32();
                 var key = ByteBuffer.NewAsync(new byte[prefixLen + keyLengthWithoutPrefix]);
                 Array.Copy(prevKey.Buffer, prevKey.Offset, key.Buffer, key.Offset, prefixLen);
                 reader.ReadBlock(key.SubBuffer(prefixLen));
                 prevKey = key;
                 return(new BTreeLeafMember
                 {
                     Key = key.ToByteArray(),
                     ValueFileId = reader.ReadVUInt32(),
                     ValueOfs = reader.ReadVUInt32(),
                     ValueSize = reader.ReadVInt32()
                 });
             });
         }
         if (reader.Eof)
         {
             return(true);
         }
         if (reader.ReadInt32() == EndOfIndexFileMarker)
         {
             return(true);
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }