/// <summary> /// try to push downstream, if failed then try to pull upstream /// </summary> private void TryPushFrame() { var bufferSize = _buffer.Count; if (bufferSize >= _frameSize) { PushFrame(); } else if (bufferSize >= _stage._minimumChunkSize) { var iterator = _buffer.Slice(_stage._lengthFieldOffset).GetEnumerator(); var parsedLength = _stage._intDecoder(iterator, _stage._lengthFieldLength); _frameSize = _stage._computeFrameSize.HasValue ? _stage._computeFrameSize.Value(_buffer.Slice(0, _stage._lengthFieldOffset).ToArray(), parsedLength) : parsedLength + _stage._minimumChunkSize; if (_frameSize > _stage._maximumFramelength) { FailStage(new FramingException( $"Maximum allowed frame size is {_stage._maximumFramelength} but decoded frame header reported size {_frameSize}")); } else if (_stage._computeFrameSize.IsEmpty && parsedLength < 0) { FailStage(new FramingException( $"Decoded frame header reported negative size {parsedLength}")); } else if (_frameSize < _stage._minimumChunkSize) { FailStage(new FramingException( $"Computed frame size {_frameSize} is less than minimum chunk size {_stage._minimumChunkSize}")); } else if (bufferSize >= _frameSize) { PushFrame(); } else { TryPull(); } } else { TryPull(); } }
/// <summary> /// try to push downstream, if failed then try to pull upstream /// </summary> private void TryPushFrame() { var bufferSize = _buffer.Count; if (bufferSize >= _frameSize) { PushFrame(); } else if (bufferSize >= _stage._minimumChunkSize) { var iterator = _buffer.Slice(_stage._lengthFieldOffset).GetEnumerator(); var parsedLength = _stage._intDecoder(iterator, _stage._lengthFieldLength); _frameSize = parsedLength + _stage._minimumChunkSize; if (_frameSize > _stage._maximumFramelength) { FailStage(new FramingException( $"Maximum allowed frame size is {_stage._maximumFramelength} but decoded frame header reported size {_frameSize}")); } else if (parsedLength < 0) { FailStage(new FramingException( $"Decoded frame header reported negative size {parsedLength}")); } else if (bufferSize >= _frameSize) { PushFrame(); } else { TryPull(); } } else { TryPull(); } }