Exemplo n.º 1
0
 private void MessageReceived(DAPMessage message)
 {
     if (message is DAPRequest)
     {
         try
         {
             HandleRequest(message as DAPRequest);
         }
         catch (RequestFailedException e)
         {
             Stream.SendReply(message as DAPRequest, e.Message);
         }
         catch (Exception e)
         {
             LogError(e.ToString());
             Stream.SendReply(message as DAPRequest, e.ToString());
         }
     }
     else if (message is DAPEvent)
     {
         HandleEvent(message as DAPEvent);
     }
     else
     {
         throw new InvalidDataException("DAP replies not handled");
     }
 }
Exemplo n.º 2
0
        public static char[] Serialize(DAPMessage message)
        {
            using (var ms = new MemoryStream())
            {
                using (var textWriter = new StreamWriter(ms))
                    using (var jsonWriter = new JsonTextWriter(textWriter))
                    {
                        var serializer = new JsonSerializer();
                        serializer.Serialize(jsonWriter, message);
                    }

                var bytes = ms.ToArray();
                return(Encoding.UTF8.GetChars(bytes));
            }
        }
Exemplo n.º 3
0
        private void ProcessPayload(char[] payload)
        {
            if (LogStream != null)
            {
                using (var writer = new StreamWriter(LogStream, Encoding.UTF8, 0x1000, true))
                {
                    writer.Write(" DAP >>> ");
                    writer.Write(payload);
                    writer.Write("\r\n");
                }
            }

            DAPMessage message = null;

            try
            {
                message = DAPMessageSerializer.Unserialize(payload);
            }
            catch (DAPUnknownMessageException e)
            {
                if (LogStream != null)
                {
                    using (var writer = new StreamWriter(LogStream, Encoding.UTF8, 0x1000, true))
                    {
                        writer.WriteLine(" DAP !!! Could not decode DAP message: " + e.Message);
                    }
                }

                if (e.Type == "request")
                {
                    SendErrorReply(e.Seq, e.MessageType, e.Message);
                }

                IncomingSeq++;
                return;
            }

            if (message.seq != IncomingSeq)
            {
                throw new InvalidDataException($"DAP sequence number mismatch; got {message.seq} expected {IncomingSeq}");
            }

            IncomingSeq++;
            MessageReceived(message);
        }
Exemplo n.º 4
0
        public void Send(DAPMessage message)
        {
            message.seq = OutgoingSeq++;
            var encoded = DAPMessageSerializer.Serialize(message);

            if (LogStream != null)
            {
                using (var writer = new StreamWriter(LogStream, Encoding.UTF8, 0x1000, true))
                {
                    writer.Write(" DAP <<< ");
                    writer.Write(encoded);
                    writer.Write("\r\n");
                }
            }

            Console.Write($"Content-Length: {encoded.Length}\r\n\r\n");
            Console.Write(encoded);
        }