Beispiel #1
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);
        }
Beispiel #2
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);
        }