public void Insert <T>(byte[] key, T value) { Interlocked.Increment(ref Counter); var entry = new DBEntry { Key = key, Value = value }; //Add to cache lock (LockObject) { Cache[key] = entry; } ThreadPool.QueueUserWorkItem(state => { var bytes = Serialization.Serialize(value); bytes = Compression.CompressGZip(bytes); var tx = new Transaction() { Kind = TransactionKind.Write, Key = key, Value = bytes }; TransactionQueue.Add(tx); }); }
internal void Serialize(BinaryWriter writer) { using (var stream = new MemoryStream()) { using (var temp = new BinaryWriter(stream)) { temp.WriteBigInteger(Height); temp.Write(Timestamp.Value); temp.WriteHash(PreviousHash); temp.WriteAddress(ChainAddress); temp.WriteVarInt(Protocol); temp.Write((ushort)_transactionHashes.Count); foreach (var hash in _transactionHashes) { temp.WriteHash(hash); var evts = GetEventsForTransaction(hash).ToArray(); temp.Write((ushort)evts.Length); foreach (var evt in evts) { evt.Serialize(temp); } int resultLen = _resultMap.ContainsKey(hash) ? _resultMap[hash].Length : -1; temp.Write((short)resultLen); if (resultLen > 0) { var result = _resultMap[hash]; temp.WriteByteArray(result); } } temp.Write((ushort)_oracleData.Count); foreach (var entry in _oracleData) { temp.WriteVarString(entry.URL); temp.WriteByteArray(entry.Content); } } var bytes = stream.ToArray(); var compressed = Compression.CompressGZip(bytes); writer.WriteByteArray(compressed); } }