public bool ShouldPass(int channel, IContentHeader contentHeader, out IContentMethod method) { if (contentHeader.SentOnValidChannel(channel) == false) { throw new CommandInvalidException($"{ contentHeader.GetType()} cannot be sent on channel {channel}."); } if (_expectationManager.IsExpecting <ContentHeaderExpectation>(channel) == false) { method = default; return(false); } _contentMethodStates[channel].SetContentHeader(contentHeader); if (contentHeader.BodySize > 0) { _expectationManager.Set(channel, new ContentBodyExpectation(contentHeader.BodySize)); method = default; return(false); } method = _contentMethodStates[channel]; _contentMethodStates.Remove(channel); _expectationManager.Set(channel, new MethodExpectation(_expectedMethodManager.GetExpectingMethodsFor(method.GetType()))); return(true); }
public bool ShouldPass(int channel, IContentBody contentBody, out IContentMethod method) { if (contentBody.SentOnValidChannel(channel) == false) { throw new CommandInvalidException($"{ contentBody.GetType()} cannot be sent on channel {channel}."); } if (_expectationManager.IsExpecting <ContentBodyExpectation>(channel) == false) { method = default; return(false); } var contentBodyExpectation = _expectationManager.Get <ContentBodyExpectation>(channel); var size = contentBody.Payload.Length; if (size > contentBodyExpectation.Size) { throw new FrameErrorException($"Invalid content body frame size. Expected {contentBodyExpectation.Size}, got {size}."); } if (size + 1 > _frameMax) { throw new FrameErrorException($"Invalid content body frame size. Maximum frame size is {_frameMax}. Current frame size was {size + 1}."); } _contentMethodStates[channel].AddContentBody(contentBody); if (size == contentBodyExpectation.Size) { method = _contentMethodStates[channel]; _expectationManager.Set(channel, new MethodExpectation(_expectedMethodManager.GetExpectingMethodsFor(method.GetType()))); _contentMethodStates.Remove(channel); return(true); } _expectationManager.Set(channel, new ContentBodyExpectation(contentBodyExpectation.Size - size)); method = default; return(false); }