summaryrefslogtreecommitdiff
path: root/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/StreamMessageProducer.h
blob: 439a9f1b0ebf00517dffcca491060007961e6c71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
	

};