private bool RawMessageReady() { // Destroy content of the old message. m_inProgress.Close(); // Read new message. If there is none, return false. // Note that new state is set only if write is successful. That way // unsuccessful write will cause retry on the next state machine // invocation. if (m_msgSource == null) { return(false); } bool result = m_msgSource.PullMsg(ref m_inProgress); if (!result) { m_inProgress.InitEmpty(); return(false); } m_inProgress.ResetFlags(MsgFlags.Shared | MsgFlags.More | MsgFlags.Identity); NextStep(null, 0, RawMessageSizeReadyState, true); return(true); }
private bool MessageReady() { // Release the content of the old message. m_inProgress.Close(); m_tmpbuf.Reset(); // Read new message. If there is none, return false. // Note that new state is set only if write is successful. That way // unsuccessful write will cause retry on the next state machine // invocation. if (m_msgSource == null) { m_inProgress.InitEmpty(); return(false); } bool messagedPulled = m_msgSource.PullMsg(ref m_inProgress); if (!messagedPulled) { m_inProgress.InitEmpty(); return(false); } int protocolFlags = 0; if (m_inProgress.HasMore) { protocolFlags |= V2Protocol.MoreFlag; } if (m_inProgress.Size > 255) { protocolFlags |= V2Protocol.LargeFlag; } m_tmpbuf[0] = (byte)protocolFlags; // Encode the message length. For messages less then 256 bytes, // the length is encoded as 8-bit unsigned integer. For larger // messages, 64-bit unsigned integer in network byte order is used. int size = m_inProgress.Size; if (size > 255) { m_tmpbuf.PutLong(Endian, size, 1); NextStep(m_tmpbuf, 9, SizeReadyState, false); } else { m_tmpbuf[1] = (byte)(size); NextStep(m_tmpbuf, 2, SizeReadyState, false); } return(true); }
private bool MessageReady() { // Release the content of the old message. m_inProgress.Close(); m_tmpbuf.Reset(); // Read new message. If there is none, return false. // Note that new state is set only if write is successful. That way // unsuccessful write will cause retry on the next state machine // invocation. if (m_msgSource == null) { m_inProgress.InitEmpty(); return(false); } bool messagedPulled = m_msgSource.PullMsg(ref m_inProgress); if (!messagedPulled) { m_inProgress.InitEmpty(); return(false); } // Get the message size. int size = m_inProgress.Size; // Account for the 'flags' byte. size++; // For messages less than 255 bytes long, write one byte of message size. // For longer messages write 0xff escape character followed by 8-byte // message size. In both cases 'flags' field follows. if (size < 255) { m_tmpbuf[0] = (byte)size; m_tmpbuf[1] = (byte)(m_inProgress.Flags & MsgFlags.More); NextStep(m_tmpbuf, 2, SizeReadyState, false); } else { m_tmpbuf[0] = 0xff; m_tmpbuf.PutLong(Endian, size, 1); m_tmpbuf[9] = (byte)(m_inProgress.Flags & MsgFlags.More); NextStep(m_tmpbuf, 10, SizeReadyState, false); } return(true); }