-
Notifications
You must be signed in to change notification settings - Fork 1
/
json2struct.h
57 lines (46 loc) · 1.09 KB
/
json2struct.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
55
56
57
/***
*
* !!!!!!IMPORTANT!!!!!!
* "Schema" should be pre-defined and cannot be changed to other name
*
*
**/
#ifndef DATACONVERTOR_H_
#define DATACONVERTOR_H_
#include <iostream>
#include <string>
#include <vector>
#include "includes/optional_json.h"
#pragma pack(push,1)
struct SampleStruct {
long timestamp;
bool active;
char name[7];
// std::string name;
int value;
};
struct Schema {
int id;
SampleStruct data;
// std::vector<SampleStruct> vector_data;
};
#pragma pack(pop)
void from_json(const nlohmann::json& j, SampleStruct& value) {
j.at("timestamp").get_to(value.timestamp);
j.at("active").get_to(value.active);
std::string name = j["name"];
memcpy(value.name, name.c_str(), sizeof(value.name));
// j.at("name").get_to(value.name);
j.at("value").get_to(value.value);
}
void from_json(const nlohmann::json& j, Schema& value) {
j.at("id").get_to(value.id);
j.at("data").get_to(value.data);
}
static bool _DEBUG_ = false;
extern "C" {
const char* test(char *source);
const char* parse(char *source, int &ret_size);
void set_debug(bool debug);
}
#endif //