System.Text.Decoder.GetChars C# (CSharp) Method

GetChars() private method

private GetChars ( byte bytes, int byteCount, char chars, int charCount, bool flush ) : int
bytes byte
byteCount int
chars char
charCount int
flush bool
return int
        public virtual unsafe int GetChars(byte* bytes, int byteCount,
                                              char* chars, int charCount, bool flush)
        {
            // Validate input parameters
            if (chars == null || bytes == null)
                throw new ArgumentNullException(chars == null ? "chars" : "bytes",
                    Environment.GetResourceString("ArgumentNull_Array"));

            if (byteCount < 0 || charCount < 0)
                throw new ArgumentOutOfRangeException((byteCount<0 ? "byteCount" : "charCount"),
                    Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));

            // Get the byte array to convert
            byte[] arrByte = new byte[byteCount];

            int index;
            for (index = 0; index < byteCount; index++)
                arrByte[index] = bytes[index];

            // Get the char array to fill
            char[] arrChar = new char[charCount];

            // Do the work
            int result = GetChars(arrByte, 0, byteCount, arrChar, 0, flush);

            // The only way this could fail is a bug in GetChars
            BCLDebug.Assert(result <= charCount, "Returned more chars than we have space for");

            // Copy the char array
            // WARNING: We MUST make sure that we don't copy too many chars.  We can't
            // rely on result because it could be a 3rd party implimentation.  We need
            // to make sure we never copy more than charCount chars no matter the value
            // of result
            if (result < charCount)
                charCount = result;

            // We check both result and charCount so that we don't accidentally overrun
            // our pointer buffer just because of any GetChars bug.
            for (index = 0; index < charCount; index++)
                chars[index] = arrChar[index];

            return charCount;
        }

Same methods

Decoder::GetChars ( byte bytes, int byteIndex, int byteCount, char chars, int charIndex ) : int
Decoder::GetChars ( byte bytes, int byteIndex, int byteCount, char chars, int charIndex, bool flush ) : int

Usage Example

示例#1
0
        private string Recieve(Socket RecieveSocket)
        {
            string[] Splitter;
            string   FullREC = "";

            byte[] buffer = new byte[RecieveSocket.Available];
            int    iRx    = RecieveSocket.Receive(buffer);

            char[] chars          = new char[iRx];
            System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
            int charLen           = d.GetChars(buffer, 0, iRx, chars, 0);

            System.String Recieved = new System.String(chars);
            FullREC += Recieved;
            Splitter = FullREC.Split('\a');
            while (Splitter[Splitter.Length - 1] != "MSGEND")
            {
                buffer   = new byte[RecieveSocket.Available];
                iRx      = RecieveSocket.Receive(buffer);
                chars    = new char[iRx];
                charLen  = d.GetChars(buffer, 0, iRx, chars, 0);
                Recieved = new System.String(chars);
                FullREC += Recieved;
                Splitter = FullREC.Split('\a');
            }
            return(FullREC);
        }
All Usage Examples Of System.Text.Decoder::GetChars