/// <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 Restart() { _valueSize = _transaction.GetValueSize(); if (_valueSize < 0) { _valueSize = 0; } _ofs = 0; FillBuffer(); }
/// <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 static byte[] ReadValue(this IKeyValueDBTransaction transaction) { long valueSize = transaction.GetValueSize(); if (valueSize < 0) { return(null); } if ((int)valueSize != valueSize) { throw new BTDBException("Value is bigger then 2GB does not fit in byte[]"); } var result = new byte[valueSize]; transaction.ReadValue(0, (int)valueSize, result, 0); return(result); }
public long GetValueSize() { LogSimpleOperation(KVReplayOperation.GetValueSize); return(_tr.GetValueSize()); }