Exemplo n.º 1
0
        internal unsafe void AppendExtraBuffer(byte *buffer, int bufferLength)
        {
            // Then convert the bytes to chars
            int   charLen = CurrentEncoding.GetMaxCharCount(bufferLength);
            char *charPtr = stackalloc char[charLen];

            charLen = CurrentEncoding.GetChars(buffer, bufferLength, charPtr, charLen);

            // Ensure our buffer is large enough to hold all of the data
            if (IsUnprocessedBufferEmpty())
            {
                _startIndex = _endIndex = 0;
            }
            else
            {
                Debug.Assert(_endIndex > 0);
                int spaceRemaining = _unprocessedBufferToBeRead.Length - _endIndex;
                if (spaceRemaining < charLen)
                {
                    Array.Resize(ref _unprocessedBufferToBeRead, _unprocessedBufferToBeRead.Length * 2);
                }
            }

            // Copy the data into our buffer
            Marshal.Copy((IntPtr)charPtr, _unprocessedBufferToBeRead, _endIndex, charLen);
            _endIndex += charLen;
        }
Exemplo n.º 2
0
        /// <summary> Reads the buffer in the raw mode. </summary>
        unsafe void ReadExtraBuffer()
        {
            Debug.Assert(IsExtraBufferEmpty());

            byte *bufPtr = stackalloc byte[BytesToBeRead];
            int   result;

            Interop.CheckIo(result = Interop.Sys.ReadStdinUnbuffered(bufPtr, BytesToBeRead));

            Debug.Assert(result > 0 && result <= BytesToBeRead);

            // Now we need to convert the byte buffer to char buffer.
            fixed(char *unprocessedBufPtr = _unprocessedBufferToBeRead)
            {
                _startIndex = 0;
                _endIndex   = CurrentEncoding.GetChars(bufPtr, result, unprocessedBufPtr, _unprocessedBufferToBeRead.Length) - 1;
            }
        }