Пример #1
0
        private void OnString(State nextState)
        {
            int Decode(ref byte[] dst)
            {
                if (_huffman)
                {
                    return(Huffman.Decode(new ReadOnlySpan <byte>(_stringOctets, 0, _stringLength), ref dst));
                }
                else
                {
                    if (dst.Length < _stringLength)
                    {
                        dst = new byte[Math.Max(_stringLength, dst.Length * 2)];
                    }

                    Buffer.BlockCopy(_stringOctets, 0, dst, 0, _stringLength);
                    return(_stringLength);
                }
            }

            try
            {
                if (_state == State.HeaderName)
                {
                    _headerNameLength = Decode(ref _headerNameOctets);
                    _headerName       = _headerNameOctets;
                }
                else
                {
                    _headerValueLength = Decode(ref _headerValueOctets);
                }
            }
            catch (HuffmanDecodingException ex)
            {
                // Error in huffman encoding.
                throw new HPackDecodingException(SR.net_http_hpack_huffman_decode_failed, ex);
            }

            _state = nextState;
        }