/// <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; }
/// <summary> /// Initializes a new instance of the <see cref="StringDecoder" /> class with the specified character /// set.. /// </summary> /// <param name="encoding">Encoding.</param> public StringDecoder(Encoding encoding) { if (encoding is null) { CThrowHelper.ThrowNullReferenceException(CExceptionArgument.encoding); } _encoding = encoding; }
static void ValidateDelimiter(IByteBuffer delimiter) { if (delimiter is null) { CThrowHelper.ThrowNullReferenceException(CExceptionArgument.delimiter); } if (!delimiter.IsReadable()) { CThrowHelper.ThrowArgumentException_EmptyDelimiter(); } }