public static string ExtractAsString(this ProducerConsumerBuffer pcb, Encoding encoding = null)
        {
            var result = pcb.PeekString(encoding);

            pcb.Clear();
            return(result);
        }
        /// <summary>
        /// Returns the entire <see cref="ProducerConsumerBuffer"/> buffer as string. Does not consume.
        /// </summary>
        public static string PeekString(this ProducerConsumerBuffer pcb, Encoding encoding = null)
        {
            if (encoding == null)
            {
                encoding = Encoding.ASCII;
            }

            byte[] buffer;
            int    offset;
            int    count = pcb.GetReadPtr(out buffer, out offset);

            if (count == 0)
            {
                return("");
            }

            return(encoding.GetString(buffer, offset, count));
        }