summaryrefslogtreecommitdiff
path: root/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/StreamMessageProducer.h
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/StreamMessageProducer.h')
-rw-r--r--graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/StreamMessageProducer.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/StreamMessageProducer.h b/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/StreamMessageProducer.h
new file mode 100644
index 0000000000..439a9f1b0e
--- /dev/null
+++ b/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/StreamMessageProducer.h
@@ -0,0 +1,48 @@
+#pragma once
+#include <string>
+#include <functional>
+#include "MessageProducer.h"
+#include <iostream>
+#include <memory>
+#include "MessageIssue.h"
+
+namespace lsp {
+ class istream;
+}
+
+class StreamMessageProducer : public MessageProducer
+{
+public:
+ struct Headers
+ {
+ int contentLength = -1;
+ std::string charset;
+ void clear()
+ {
+ contentLength = -1;
+ charset.clear();
+ }
+ };
+ bool handleMessage(Headers& headers, MessageConsumer callBack);
+ StreamMessageProducer(
+ MessageIssueHandler& message_issue_handler, std::shared_ptr < lsp::istream> _input)
+ : issueHandler(message_issue_handler),
+ input(_input)
+ {
+ }
+ StreamMessageProducer(
+ MessageIssueHandler& message_issue_handler)
+ : issueHandler(message_issue_handler)
+ {
+ }
+
+ bool keepRunning = false;
+ void listen(MessageConsumer) override;
+ void bind(std::shared_ptr < lsp::istream>);
+ void parseHeader(std::string& line, Headers& headers);
+private:
+ MessageIssueHandler& issueHandler;
+ std::shared_ptr < lsp::istream> input;
+
+
+};