public static void Verify(this BinaryReader reader, uint expected) { var actual = reader.ReadUInt32(); if (actual != expected) { throw ProtocolException.Create(reader, expected, actual); } }
public static void Verify(this BinaryReader reader, uint expected) { var positionBefore = reader.BaseStream.Position; var actual = reader.ReadUInt32(); if (actual != expected) { throw ProtocolException.Create(expected, actual, positionBefore); } }
/// <summary> /// Receive specific message matching MessageType. Note! This filters away all ServerMessages to get to that particular message. /// </summary> /// <param name="messageType"></param> /// <returns>FileZilla message matching MessageType</returns> public FileZillaMessage ReceiveMessage(MessageType messageType) { for (int retry = 0; retry < 5; retry++) { var messages = ReceiveMessages(); FileZillaMessage fileZillaMessage = null; bool allMessagesHandled = true; foreach (FileZillaMessage check in messages) { if (check.MessageOrigin == MessageOrigin.ServerReply && check.MessageType == messageType) { if (fileZillaMessage != null) { throw new ProtocolException("Multiple commands matched"); } fileZillaMessage = check; } else { if (!HandleUnmatchedMessage(messageType, check)) { allMessagesHandled = false; break; } } } if (!allMessagesHandled) { throw ProtocolException.Create(messageType, messages); } if (fileZillaMessage != null) { return(fileZillaMessage); } // Jedi mind trick: This is not the message you are looking for: Do it all again } throw new ProtocolException("Unable to receive message: " + messageType); }