Пример #1
0
        /// <summary>
        /// Reads the string async.
        /// </summary>
        /// <returns> </returns>
        private async Task<string> ReadStringAsync(Task<ushort> lengthTask)
        {
            //read length
            ushort len = await lengthTask.AutoConfigureAwait();
            if(0 == len)
                return string.Empty;

            //read the string segment
            if(!TryGetSegmentFromBuffer(len))
                await ReadSegmentAsync(len).AutoConfigureAwait();

            //return parsed string
            return Encoding.UTF8.GetString(_lastReadSegment.Array, _lastReadSegment.Offset, _lastReadSegment.Count);
        }