/// <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(); } }
public void PeekKey(int ofs, out int len, out byte[] buf, out int bufOfs) { lock (_log) { _log.WriteUInt8((byte)KVReplayOperation.PeekKey); _log.WriteVUInt32(TrIndex); _log.WriteVInt32(ofs); _log.FlushBuffer(); } _tr.PeekKey(ofs, out len, out buf, out bufOfs); }
protected override sealed void FillBuffer() { if (_ofs == _keySize) { Pos = 0; End = -1; return; } _transaction.PeekKey(_ofs, out End, out Buf, out Pos); _ofs += End; End += Pos; }
ulong ReadOidFromCurrentKeyInTransaction() { int len; byte[] buf; int bufOfs; _keyValueTr.PeekKey(0, out len, out buf, out bufOfs); ulong oid = PackUnpack.UnpackVUInt(buf, ref bufOfs); return(oid); }
/// <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(); } }