/// <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 PeekValue(long ofs, out int len, out byte[] buf, out int bufOfs)
 {
     lock (_log)
     {
         _log.WriteUInt8((byte)KVReplayOperation.PeekValue);
         _log.WriteVUInt32(TrIndex);
         _log.WriteVInt64(ofs);
         _log.FlushBuffer();
     }
     _tr.PeekValue(ofs, out len, out buf, out bufOfs);
 }
Exemple #3
0
 protected override sealed void FillBuffer()
 {
     if (_ofs == _valueSize)
     {
         Pos = 0;
         End = -1;
         return;
     }
     _transaction.PeekValue(_ofs, out End, out Buf, out Pos);
     _ofs += End;
     End  += Pos;
 }
 /// <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();
     }
 }