public AppendBodyFragment ( byte fragment ) : void | ||
fragment | byte | |
return | void |
public Command HandleFrame(Frame f) { switch (m_state) { case AssemblyState.ExpectingMethod: { if (f.Type != Constants.FrameMethod) { throw new UnexpectedFrameException(f); } m_command.Method = m_protocol.DecodeMethodFrom(f.GetReader()); m_state = m_command.Method.HasContent ? AssemblyState.ExpectingContentHeader : AssemblyState.Complete; return(CompletedCommand()); } case AssemblyState.ExpectingContentHeader: { if (f.Type != Constants.FrameHeader) { throw new UnexpectedFrameException(f); } NetworkBinaryReader reader = f.GetReader(); m_command.Header = m_protocol.DecodeContentHeaderFrom(reader); m_remainingBodyBytes = m_command.Header.ReadFrom(reader); UpdateContentBodyState(); return(CompletedCommand()); } case AssemblyState.ExpectingContentBody: { if (f.Type != Constants.FrameBody) { throw new UnexpectedFrameException(f); } byte[] fragment = f.Payload; m_command.AppendBodyFragment(fragment); if ((ulong)fragment.Length > m_remainingBodyBytes) { throw new MalformedFrameException (string.Format("Overlong content body received - {0} bytes remaining, {1} bytes received", m_remainingBodyBytes, fragment.Length)); } m_remainingBodyBytes -= (ulong)fragment.Length; UpdateContentBodyState(); return(CompletedCommand()); } case AssemblyState.Complete: default: #if NETFX_CORE Debug.WriteLine("Received frame in invalid state {0}; {1}", m_state, f); #else Trace.Fail(string.Format("Received frame in invalid state {0}; {1}", m_state, f)); #endif return(null); } }
public Command HandleFrame(InboundFrame f) { switch (m_state) { case AssemblyState.ExpectingMethod: { if (!f.IsMethod()) { throw new UnexpectedFrameException(f); } m_command.Method = m_protocol.DecodeMethodFrom(f.GetReader()); m_state = m_command.Method.HasContent ? AssemblyState.ExpectingContentHeader : AssemblyState.Complete; return(CompletedCommand()); } case AssemblyState.ExpectingContentHeader: { if (!f.IsHeader()) { throw new UnexpectedFrameException(f); } NetworkBinaryReader reader = f.GetReader(); m_command.Header = m_protocol.DecodeContentHeaderFrom(reader); m_remainingBodyBytes = m_command.Header.ReadFrom(reader); UpdateContentBodyState(); return(CompletedCommand()); } case AssemblyState.ExpectingContentBody: { if (!f.IsBody()) { throw new UnexpectedFrameException(f); } m_command.AppendBodyFragment(f.Payload); if ((ulong)f.Payload.Length > m_remainingBodyBytes) { throw new MalformedFrameException (string.Format("Overlong content body received - {0} bytes remaining, {1} bytes received", m_remainingBodyBytes, f.Payload.Length)); } m_remainingBodyBytes -= (ulong)f.Payload.Length; UpdateContentBodyState(); return(CompletedCommand()); } case AssemblyState.Complete: default: return(null); } }