-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMQTTDataParser.h
54 lines (45 loc) · 1.24 KB
/
MQTTDataParser.h
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
49
50
51
52
53
54
/**
* @file MQTTDataParser.h
* @Author BeeeOn team - Peter Tisovcik <[email protected]>
* @date September, 2016
*/
#ifndef MQTT_DATA_PARSER_H
#define MQTT_DATA_PARSER_H
#include <iostream>
#include <string>
#include <Poco/JSON/JSON.h>
#include <Poco/JSON/Parser.h>
#include <Poco/Logger.h>
#include "utils.h"
/*
* The class impelements JSON parser for MQTTDataParser. Parses
* JSON messages from mosquitto and mosquitto generates messages
* that came from the server
*/
class MQTTDataParser {
public:
MQTTDataParser();
/*
* It parses JSON message from MQTT to IOTMessage struct.
* @param &data JSON message string
* @return Parsed message - IOTMessage struct
*/
IOTMessage parseMessage(const std::string& data) const;
private:
Poco::Logger& log;
/*
* It parses message and return JSON Object.
* @param &data JSON message string
* @return JSON Object
*/
Poco::JSON::Object::Ptr parseJsonObject(const std::string& data) const;
/*
* Get string from JSON Object.
* @param jsonObject Object which contains parsed JSON message.
* @parma &key JSON attribute which contains value
* @return searched value
*/
std::string extractString(Poco::JSON::Object::Ptr jsonObject,
const std::string& key) const;
};
#endif