public void CompressedMemoryCanBeDecompressed()
        {
            const string content = "some string to be compressed";
            var          buffer  = Encoding.ASCII.GetBytes(content);
            var          memory  = new Memory <byte>(buffer);

            var compressed   = compressor.Process(memory);
            var decompressed = decompressor.Process(compressed.Memory);

            Encoding.ASCII.GetString(decompressed.Memory.Span).ShouldBe(content);
        }
        int ForEachByteDesc0(int rStart, int rEnd, IByteProcessor processor)
        {
            for (; rStart >= rEnd; --rStart)
            {
                if (!processor.Process(this._GetByte(rStart)))
                {
                    return(rStart);
                }
            }

            return(-1);
        }
        int ForEachByteAsc0(int start, int end, IByteProcessor processor)
        {
            for (; start < end; ++start)
            {
                if (!processor.Process(this._GetByte(start)))
                {
                    return(start);
                }
            }

            return(-1);
        }
        private void ProcessChunk()
        {
            try
            {
                foreach (var jobBatchItem in jobQueue.GetConsumingEnumerable())
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    var processed = new ProcessedBatchItem
                    {
                        JobBatchItemId = jobBatchItem.JobBatchItemId,
                        Processed      = byteProcessor.Process(jobBatchItem.Memory)
                    };
                    jobBatchItem.ReleaseBuffer();

                    if (!cancellationToken.IsCancellationRequested)
                    {
                        outputBuffer.SubmitProcessedBatchItem(processed);
                    }
                }
            }
            catch (Exception e)
            {
                jobContext.Failure(e, e.Message);
                cancellationTokenSource.Cancel();
            }
            finally
            {
                countdown.Signal();
            }

            outputBuffer.SubmitCompleted();
        }