-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjsonreader.h
More file actions
43 lines (32 loc) · 1 KB
/
jsonreader.h
File metadata and controls
43 lines (32 loc) · 1 KB
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
// Copyright 2013 MakerBot Industries
#ifndef SRC_MAIN_CPP_JSONREADER_H_
#define SRC_MAIN_CPP_JSONREADER_H_
#include <cstddef>
#include <sstream>
#include <stack>
#include <string>
#include "jsonrpc/jsonrpc.h"
#include "jsonrpc/jsonrpcstream.h"
class JsonReader : public JsonRpcStream {
public:
JSONRPC_API JsonReader(JsonRpcPrivate &);
JSONRPC_API void feed(char ch);
JSONRPC_API void feed(char const *, std::size_t);
JSONRPC_API void feed(std::string const &);
JSONRPC_API void feedeof(void);
JSONRPC_API void setDelimiter(char);
private:
enum State { S0, S1, S2, S3 };
void reset(void);
bool transition(char ch);
void send(void);
JsonRpcPrivate & m_jsonRpcPrivate;
State m_state;
std::stack <char> m_stack;
std::ostringstream m_buffer;
char m_packetDelimiter = '\n'; //by default use \n char as sync sequence
// Disable copy constructor and assignment.
JsonReader(const JsonReader &other);
JsonReader & operator=(JsonReader const &);
};
#endif // SRC_MAIN_CPP_JSONREADER_H_