System.Runtime.Remoting.Channels.Http.HttpChannelHelper.CharacterHexDigitToDecimal C# (CSharp) Метод

CharacterHexDigitToDecimal() статический приватный Метод

static private CharacterHexDigitToDecimal ( byte b ) : int
b byte
Результат int
        internal static int CharacterHexDigitToDecimal(byte b)
        {
            switch ((char)b)
            {
            case 'F': return 15;
            case 'E': return 14;
            case 'D': return 13;
            case 'C': return 12;
            case 'B': return 11;
            case 'A': return 10;
            default: return b - (byte)'0';
            }
        } // CharacterHexDigitToDecimal

Usage Example

Пример #1
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int bytesRead = 0;

            while (!_bFoundEnd && (count > 0))
            {
                // see if we need to start reading a new chunk
                if (_bytesLeft == 0)
                {
                    // this loop stops when the end of line is found
                    for (;;)
                    {
                        byte b = (byte)_inputStream.ReadByte();

                        // see if this is the end of the length
                        if (b == '\r')
                        {
                            // This had better be '\n'
                            if ((char)_inputStream.ReadByte() != '\n')
                            {
                                throw new RemotingException(
                                          CoreChannel.GetResourceString(
                                              "Remoting_Http_ChunkedEncodingError"));
                            }
                            else
                            {
                                break; // we've finished reading the length
                            }
                        }
                        else
                        {
                            int value = HttpChannelHelper.CharacterHexDigitToDecimal(b);
                            // make sure value is a hex-digit
                            if ((value < 0) || (value > 15))
                            {
                                throw new RemotingException(
                                          CoreChannel.GetResourceString(
                                              "Remoting_Http_ChunkedEncodingError"));
                            }

                            // update _bytesLeft value to account for new digit on the right
                            _bytesLeft = (_bytesLeft * 16) + value;
                        }
                    }

                    if (_bytesLeft == 0)
                    {
                        // read off trailing headers and end-line
                        String trailerHeader;
                        do
                        {
                            trailerHeader = _inputStream.ReadToEndOfLine();
                        } while (!(trailerHeader.Length == 0));

                        _bFoundEnd = true;
                    }
                }

                if (!_bFoundEnd)
                {
                    int readCount         = min(_bytesLeft, count);
                    int bytesReadThisTime = _inputStream.Read(buffer, offset, readCount);
                    if (bytesReadThisTime <= 0)
                    {
                        throw new RemotingException(
                                  CoreChannel.GetResourceString(
                                      "Remoting_Http_ChunkedEncodingError"));
                    }

                    _bytesLeft -= bytesReadThisTime;
                    count      -= bytesReadThisTime;
                    offset     += bytesReadThisTime;
                    bytesRead  += bytesReadThisTime;

                    // see if the end of the chunk was found
                    if (_bytesLeft == 0)
                    {
                        // read off "\r\n"
                        char ch = (char)_inputStream.ReadByte();
                        if (ch != '\r')
                        {
                            throw new RemotingException(
                                      CoreChannel.GetResourceString(
                                          "Remoting_Http_ChunkedEncodingError"));
                        }
                        ch = (char)_inputStream.ReadByte();
                        if (ch != '\n')
                        {
                            throw new RemotingException(
                                      CoreChannel.GetResourceString(
                                          "Remoting_Http_ChunkedEncodingError"));
                        }
                    }
                }
            } // while (count > 0)

            return(bytesRead);
        } // Read
All Usage Examples Of System.Runtime.Remoting.Channels.Http.HttpChannelHelper::CharacterHexDigitToDecimal