public static PacketData Execute(Command command, Packet packet) { var executeMethod = GetExecutingMethod(command, packet); var mnemonic = executeMethod.GetCustomAttribute<ExecuteAttribute>().Mnemonic; var parsingContext = new ParsingContext(packet, mnemonic.Length); var parameters = executeMethod.GetParameters().Select(x => HandleArgumentNotResolved(parsingContext, x)).ToArray(); return (PacketData)executeMethod.Invoke(command, parameters); }
private static MethodInfo GetExecutingMethod(Command command, Packet packet) { var interestingMethods = GetExecutingMethods(command.GetType()); if(!interestingMethods.Any()) { return null; } return interestingMethods.SingleOrDefault(x => packet.Data.DataAsString.StartsWith(x.GetCustomAttribute<ExecuteAttribute>().Mnemonic, StringComparison.Ordinal)); }
public bool TryGetCommand(Packet packet, out Command command) { var commandDescriptor = availableCommands.SingleOrDefault(x => packet.Data.DataAsString.StartsWith(x.Mnemonic, StringComparison.Ordinal)); if(commandDescriptor == null) { command = null; return false; } command = GetOrCreateCommand(commandDescriptor.Method.DeclaringType); return true; }
public ParsingContext(Packet packet, int currentPosition) { Packet = packet; CurrentPosition = currentPosition; }
private void SendPacket(Packet packet) { cpu.Log(LogLevel.Debug, "Sending response to GDB: {0}", packet.Data.DataAsString); foreach(var b in packet.GetCompletePacket()) { terminal.SendByte(b); } }
public static bool TryCreate(byte[] data, byte checksum, out Packet p) { p = new Packet(new PacketData(data)); return p.CalculateChecksum() == checksum; }
public Result(Packet packet = null, bool corruptedPacket = false, bool interrupt = false) { Packet = packet; Interrupt = interrupt; CorruptedPacket = corruptedPacket; }