예제 #1
0
        /// <summary>Common constructor</summary>
        /// <param name="maxFrameLength">
        ///     The maximum length of the decoded frame
        ///     NOTE: A see <see cref="DotNetty.Codecs.TooLongFrameException" /> is thrown if the length of the frame exceeds this
        ///     value.
        /// </param>
        /// <param name="stripDelimiter">whether the decoded frame should strip out the delimiter or not</param>
        /// <param name="failFast">
        ///     If true, a <see cref="DotNetty.Codecs.TooLongFrameException" /> is
        ///     thrown as soon as the decoder notices the length of the
        ///     frame will exceed<tt>maxFrameLength</tt> regardless of
        ///     whether the entire frame has been read.
        ///     If false, a <see cref="DotNetty.Codecs.TooLongFrameException" /> is
        ///     thrown after the entire frame that exceeds maxFrameLength has been read.
        /// </param>
        /// <param name="delimiters">delimiters</param>
        public DelimiterBasedFrameDecoder(int maxFrameLength, bool stripDelimiter, bool failFast, params IByteBuffer[] delimiters)
        {
            ValidateMaxFrameLength(maxFrameLength);
            if (delimiters is null)
            {
                CThrowHelper.ThrowNullReferenceException(CExceptionArgument.delimiters);
            }

            if (0u >= (uint)delimiters.Length)
            {
                CThrowHelper.ThrowArgumentException_EmptyDelimiters();
            }

            if (IsLineBased(delimiters) && !IsSubclass())
            {
                _lineBasedDecoder = new LineBasedFrameDecoder(maxFrameLength, stripDelimiter, failFast);
                _delimiters       = null;
            }
            else
            {
                _delimiters = new IByteBuffer[delimiters.Length];
                for (int i = 0; i < delimiters.Length; i++)
                {
                    IByteBuffer d = delimiters[i];
                    ValidateDelimiter(d);
                    _delimiters[i] = d.Slice(d.ReaderIndex, d.ReadableBytes);
                }
                _lineBasedDecoder = null;
            }
            _maxFrameLength = maxFrameLength;
            _stripDelimiter = stripDelimiter;
            _failFast       = failFast;
        }