예제 #1
0
        /// <summary>
        /// Creates a new HPACK Encoder
        /// </summary>
        /// <param name="options">Encoder options</param>
        public Encoder(Options?options)
        {
            var dynamicTableSize = Defaults.DynamicTableSize;

            this._huffmanStrategy = HuffmanStrategy.IfSmaller;

            if (options.HasValue)
            {
                var opts = options.Value;
                if (opts.DynamicTableSize.HasValue)
                {
                    dynamicTableSize = opts.DynamicTableSize.Value;
                }
                if (opts.HuffmanStrategy.HasValue)
                {
                    this._huffmanStrategy = opts.HuffmanStrategy.Value;
                }
            }

            // TODO: If the size is not the default size we basically also need
            // to send a size update frame immediatly.
            // However this currently the obligation of the user of this class

            this._headerTable = new HeaderTable(dynamicTableSize);
        }
예제 #2
0
        /// <summary>
        /// Creates a new HPACK decoder
        /// </summary>
        /// <param name="options">Decoder options</param>
        public Decoder(Options?options)
        {
            var dynamicTableSize = Defaults.DynamicTableSize;

            this._dynamicTableSizeLimit = Defaults.DynamicTableSizeLimit;
            var maxStringLength         = Defaults.MaxStringLength;
            ArrayPool <byte> bufferPool = null;

            if (options.HasValue)
            {
                var opts = options.Value;
                if (opts.DynamicTableSize.HasValue)
                {
                    dynamicTableSize = opts.DynamicTableSize.Value;
                }
                if (opts.DynamicTableSizeLimit.HasValue)
                {
                    this._dynamicTableSizeLimit = opts.DynamicTableSizeLimit.Value;
                }
                if (opts.MaxStringLength.HasValue)
                {
                    maxStringLength = opts.MaxStringLength.Value;
                }
                if (opts.BufferPool != null)
                {
                    bufferPool = opts.BufferPool;
                }
            }

            if (bufferPool == null)
            {
                bufferPool = ArrayPool <byte> .Shared;
            }

            this._stringDecoder = new StringDecoder(maxStringLength, bufferPool);

            if (dynamicTableSize > this._dynamicTableSizeLimit)
            {
                throw new ArgumentException("Dynamic table size must not exceeded limit");
            }

            this._headerTable = new HeaderTable(dynamicTableSize);
        }