// Reads the next chunk in a nvarchar(max) data stream. // This call must be preceeded by a call to ReadPlpLength or ReadDataLength. // Will not start reading into the next chunk if bytes requested is larger than // the current chunk length. Do another ReadPlpLength, ReadPlpUnicodeChars in that case. // Returns the actual chars read private bool TryReadPlpUnicodeCharsChunk(char[] buff, int offst, int len, TdsParserStateObject stateObj, out int charsRead) { Debug.Assert((buff == null && len == 0) || (buff.Length >= offst + len), "Invalid length sent to ReadPlpUnicodeChars()!"); Debug.Assert((stateObj._longlen != 0) && (stateObj._longlen != TdsEnums.SQL_PLP_NULL), "Out of sync plp read request"); if (stateObj._longlenleft == 0) { Debug.Assert(false, "Out of sync read request"); charsRead = 0; return true; } charsRead = len; // stateObj._longlenleft is in bytes if ((stateObj._longlenleft >> 1) < (ulong)len) charsRead = (int)(stateObj._longlenleft >> 1); for (int ii = 0; ii < charsRead; ii++) { if (!stateObj.TryReadChar(out buff[offst + ii])) { return false; } } stateObj._longlenleft -= ((ulong)charsRead << 1); return true; }