/// <summary>
        /// Writes all key value pairs in current prefix to stream (prefix itself is not written)
        /// </summary>
        /// <param name="transaction">transaction from where export all data</param>
        /// <param name="stream">where to write it to</param>
        public static void Export(IKeyValueDBTransaction transaction, Stream stream)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanWrite)
            {
                throw new ArgumentException("stream must be writeable", "stream");
            }
            var keyValueCount = transaction.GetKeyValueCount();
            var tempbuf       = new byte[16];

            tempbuf[0] = (byte)'B';
            tempbuf[1] = (byte)'T';
            tempbuf[2] = (byte)'D';
            tempbuf[3] = (byte)'B';
            tempbuf[4] = (byte)'E';
            tempbuf[5] = (byte)'X';
            tempbuf[6] = (byte)'P';
            tempbuf[7] = (byte)'1';
            PackUnpack.PackInt64LE(tempbuf, 8, keyValueCount);
            stream.Write(tempbuf, 0, 16);
            transaction.FindFirstKey();
            for (long kv = 0; kv < keyValueCount; kv++)
            {
                var keySize = transaction.GetKeySize();
                PackUnpack.PackInt32LE(tempbuf, 0, keySize);
                stream.Write(tempbuf, 0, 4);
                long ofs = 0;
                while (ofs < keySize)
                {
                    int    len;
                    byte[] buf;
                    int    bufOfs;
                    transaction.PeekKey((int)ofs, out len, out buf, out bufOfs);
                    stream.Write(buf, bufOfs, len);
                    ofs += len;
                }
                var valueSize = transaction.GetValueSize();
                PackUnpack.PackInt64LE(tempbuf, 0, valueSize);
                stream.Write(tempbuf, 0, 8);
                ofs = 0;
                while (ofs < valueSize)
                {
                    int    len;
                    byte[] buf;
                    int    bufOfs;
                    transaction.PeekValue(ofs, out len, out buf, out bufOfs);
                    stream.Write(buf, bufOfs, len);
                    ofs += len;
                }
                transaction.FindNextKey();
            }
        }
Exemple #2
0
 public void Restart()
 {
     _keySize = _transaction.GetKeySize();
     if (_keySize < 0)
     {
         _keySize = 0;
     }
     _ofs = 0;
     FillBuffer();
 }
Exemple #3
0
        public static byte[] ReadKey(this IKeyValueDBTransaction transaction)
        {
            int keySize = transaction.GetKeySize();

            if (keySize < 0)
            {
                return(null);
            }
            var result = new byte[keySize];

            transaction.ReadKey(0, keySize, result, 0);
            return(result);
        }
 /// <summary>
 /// Writes all key value pairs in current prefix to stream (prefix itself is not written)
 /// </summary>
 /// <param name="transaction">transaction from where export all data</param>
 /// <param name="stream">where to write it to</param>
 public static void Export(IKeyValueDBTransaction transaction, Stream stream)
 {
     if (transaction == null) throw new ArgumentNullException("transaction");
     if (stream == null) throw new ArgumentNullException("stream");
     if (!stream.CanWrite) throw new ArgumentException("stream must be writeable", "stream");
     var keyValueCount = transaction.GetKeyValueCount();
     var tempbuf = new byte[16];
     tempbuf[0] = (byte)'B';
     tempbuf[1] = (byte)'T';
     tempbuf[2] = (byte)'D';
     tempbuf[3] = (byte)'B';
     tempbuf[4] = (byte)'E';
     tempbuf[5] = (byte)'X';
     tempbuf[6] = (byte)'P';
     tempbuf[7] = (byte)'1';
     PackUnpack.PackInt64LE(tempbuf, 8, keyValueCount);
     stream.Write(tempbuf, 0, 16);
     transaction.FindFirstKey();
     for (long kv = 0; kv < keyValueCount; kv++)
     {
         var keySize = transaction.GetKeySize();
         PackUnpack.PackInt32LE(tempbuf, 0, keySize);
         stream.Write(tempbuf, 0, 4);
         long ofs = 0;
         while (ofs < keySize)
         {
             int len;
             byte[] buf;
             int bufOfs;
             transaction.PeekKey((int)ofs, out len, out buf, out bufOfs);
             stream.Write(buf, bufOfs, len);
             ofs += len;
         }
         var valueSize = transaction.GetValueSize();
         PackUnpack.PackInt64LE(tempbuf, 0, valueSize);
         stream.Write(tempbuf, 0, 8);
         ofs = 0;
         while (ofs < valueSize)
         {
             int len;
             byte[] buf;
             int bufOfs;
             transaction.PeekValue(ofs, out len, out buf, out bufOfs);
             stream.Write(buf, bufOfs, len);
             ofs += len;
         }
         transaction.FindNextKey();
     }
 }
Exemple #5
0
 public int GetKeySize()
 {
     LogSimpleOperation(KVReplayOperation.GetKeySize);
     return(_tr.GetKeySize());
 }