/// <summary>
        /// Checks that the read state is valid.
        /// </summary>
        private MultiPartReadState CheckValidReadStates(MultiPartReadState state, bool statesAreValid, params MultiPartReadState[] states)
        {
            if (states == null || states.Length == 0)
            {
                return(state);
            }

            if (states.Contains(state))
            {
                return(statesAreValid ? state : throw new InvalidOperationException("Unexpected stream data; response is malformed."));
            }
            else
            {
                return(!statesAreValid ? state : throw new InvalidOperationException("Unexpected stream data; response is malformed."));
            }
        }
 /// <summary>
 /// Reads the next line and determines state.
 /// </summary>
 private async Task <MultiPartReadState> ReadNextLineAsync(bool ignoreEmpty = false)
 {
     return(_state = await ReadNextLineInternalAsync(ignoreEmpty));
 }