protected override void Dispatch(ITurtleApiMessage msg) { if (msg.GetType() == typeof(TurtleMessage)) { var tm = (TurtleMessage)msg; Console.WriteLine($"TurtleMessage: {tm.Label}"); if (!turtles.ContainsKey(tm.Label)) { turtles[tm.Label] = new Turtle(tm.Label, this); } } else if (msg.GetType() == typeof(Response)) { var rs = (Response)msg; Console.WriteLine($"Response: {rs.Label} -> {rs.Content}"); turtles[rs.Label].OnMessage(rs.Content); } }
public static void Write(ITurtleApiMessage msg, ref byte[] buffer, out int messageType, out int len) { messageType = TypeMap[msg.GetType()]; len = Writers[messageType](ref buffer, msg); }