public LogRecordStream(Stream inner, bool checksum, BufferPool bufferPool) { _inner = inner; _checksum = checksum; _bufferPool = bufferPool; _binaryReader = new BinaryReader(inner); _buffer = _bufferPool.Take(LogWriter.BlockSize); try { var type = ReadPhysicalRecord(); switch (type) { case LogRecordType.FullType: _completedRecord = true; break; case LogRecordType.StartType: _inFragmentedRecord = true; break; case LogRecordType.MiddleType: case LogRecordType.EndType: throw new CorruptedDataException("missing start of fragmented record(3)"); default: throw new ArgumentOutOfRangeException("Don't know how to handle record type: " + type); } } catch (Exception) { _bufferPool.Return(_buffer); throw; } }
public Slice(ref byte[] externalBuffer, Slice other, BufferPool bufferPool) { if (externalBuffer.Length < other.Count) { bufferPool.Return(externalBuffer); externalBuffer = bufferPool.Take(other.Count); } _array = externalBuffer; _count = other._count; _offset = 0; Buffer.BlockCopy(other.Array, other.Offset, externalBuffer, 0, other.Count); }