SSCMA-Micro CPP SDK  v2.0.0
SSCMA-Micro is a cross-platform machine learning inference framework designed for embedded devices.
ma_codec_json.h
Go to the documentation of this file.
1 #ifndef _MA_CODEC_JSON_H_
2 #define _MA_CODEC_JSON_H_
3 
4 #include <cJSON.h>
5 
6 #include "core/ma_common.h"
7 #include "porting/ma_osal.h"
8 
9 #include "ma_codec_base.h"
10 
11 namespace ma {
12 
13 class EncoderJSON final : public Encoder {
14 
15 public:
16  EncoderJSON();
17  ~EncoderJSON();
18 
19  operator bool() const override;
20 
21  ma_err_t begin() override;
22  ma_err_t begin(ma_msg_type_t type, ma_err_t code, const std::string& name) override;
23  ma_err_t begin(ma_msg_type_t type, ma_err_t code, const std::string& name, const std::string& data) override;
24  ma_err_t begin(ma_msg_type_t type, ma_err_t code, const std::string& name, uint64_t data) override;
25  ma_err_t end() override;
26  ma_err_t reset() override;
27 
28  ma_err_t remove(const std::string& key) override;
29 
30  ma_err_t write(const std::string& key, const char* buffer, size_t size) override;
31 
32 
33  ma_err_t write(const std::string& key, int8_t value) override;
34  ma_err_t write(const std::string& key, int16_t value) override;
35  ma_err_t write(const std::string& key, int32_t value) override;
36  ma_err_t write(const std::string& key, int64_t value) override;
37  ma_err_t write(const std::string& key, uint8_t value) override;
38  ma_err_t write(const std::string& key, uint16_t value) override;
39  ma_err_t write(const std::string& key, uint32_t value) override;
40  ma_err_t write(const std::string& key, uint64_t value) override;
41  ma_err_t write(const std::string& key, float value) override;
42  ma_err_t write(const std::string& key, double value) override;
43  ma_err_t write(const std::string& key, const std::string& value) override;
44  ma_err_t write(const std::string& key, ma_model_t value) override;
45  ma_err_t write(ma_perf_t value) override;
46 
47  ma_err_t write(const std::forward_list<ma_class_t>& value) override;
48  ma_err_t write(const std::forward_list<ma_point_t>& value) override;
49  ma_err_t write(const std::forward_list<ma_bbox_t>& value) override;
50  ma_err_t write(const std::forward_list<ma_keypoint3f_t>& value) override;
51 
52  ma_err_t write(const std::vector<ma_model_t>& value) override;
53 
54 
55  ma_err_t write(const std::vector<Sensor*>& value) override;
56  ma_err_t write(const Sensor* value, size_t preset) override;
57 
58 
59  ma_err_t write(const in4_info_t& value) override;
60  ma_err_t write(const in6_info_t& value) override;
61  ma_err_t write(const ma_wifi_config_t& value, int* stat = nullptr) override;
62 
63  ma_err_t write(const ma_mqtt_config_t& value, int* stat = nullptr) override;
64 
65  ma_err_t write(const ma_mqtt_topic_config_t& value) override;
66 
67 
68  ma_err_t write(int algo_id, int cat, int input_from, int tscore, int tiou) override;
69 
70 
71  const std::string& toString() const override;
72  const void* data() const override;
73  const size_t size() const override;
74 
75 private:
76  cJSON* m_root;
77  cJSON* m_data;
78  Mutex m_mutex;
79  mutable std::string m_string;
80 };
81 
82 class DecoderJSON final : public Decoder {
83 
84 public:
85  DecoderJSON();
86  ~DecoderJSON();
87 
88  operator bool() const override;
89 
90  ma_err_t begin(const void* data, size_t size) override;
91  ma_err_t begin(const std::string& str) override;
92  ma_err_t end() override;
93 
94  ma_msg_type_t type() const override;
95  ma_err_t code() const override;
96  std::string name() const override;
97 
98  ma_err_t read(const std::string& key, int8_t& value) const override;
99  ma_err_t read(const std::string& key, int16_t& value) const override;
100  ma_err_t read(const std::string& key, int32_t& value) const override;
101  ma_err_t read(const std::string& key, int64_t& value) const override;
102  ma_err_t read(const std::string& key, uint8_t& value) const override;
103  ma_err_t read(const std::string& key, uint16_t& value) const override;
104  ma_err_t read(const std::string& key, uint32_t& value) const override;
105  ma_err_t read(const std::string& key, uint64_t& value) const override;
106  ma_err_t read(const std::string& key, float& value) const override;
107  ma_err_t read(const std::string& key, double& value) const override;
108  ma_err_t read(const std::string& key, std::string& value) const override;
109  ma_err_t read(ma_perf_t& value) override;
110  ma_err_t read(std::forward_list<ma_class_t>& value) override;
111  ma_err_t read(std::forward_list<ma_point_t>& value) override;
112  ma_err_t read(std::forward_list<ma_bbox_t>& value) override;
113 
114 private:
115  std::string m_string;
116  cJSON* m_root;
117  cJSON* m_data;
118  ma_msg_type_t m_type;
119  ma_err_t m_code;
120  std::string m_name;
121  Mutex m_mutex;
122 };
123 
124 
125 } // namespace ma
126 
127 #endif // _MA_CODEC_JSON_H_
Definition: ma_codec_base.h:286
Definition: ma_codec_json.h:82
ma_msg_type_t type() const override
Definition: ma_codec_json.cpp:713
ma_err_t end() override
Definition: ma_codec_json.cpp:704
std::string name() const override
Definition: ma_codec_json.cpp:721
ma_err_t code() const override
Definition: ma_codec_json.cpp:717
~DecoderJSON()
Definition: ma_codec_json.cpp:639
ma_err_t begin(const void *data, size_t size) override
Definition: ma_codec_json.cpp:654
ma_err_t read(const std::string &key, int8_t &value) const override
Definition: ma_codec_json.cpp:725
DecoderJSON()
Definition: ma_codec_json.cpp:637
Definition: ma_codec_base.h:14
Definition: ma_codec_json.h:13
const std::string & toString() const override
Encoder type for convert to string.
Definition: ma_codec_json.cpp:143
ma_err_t begin() override
Encoder type for begin.
Definition: ma_codec_json.cpp:35
const void * data() const override
Encoder type for get data.
Definition: ma_codec_json.cpp:147
ma_err_t write(const std::string &key, const char *buffer, size_t size) override
Definition: ma_codec_json.cpp:548
ma_err_t write(const std::vector< Sensor * > &value) override
ma_err_t remove(const std::string &key) override
Encoder type for remove.
Definition: ma_codec_json.cpp:165
ma_err_t end() override
Encoder type for end.
Definition: ma_codec_json.cpp:119
~EncoderJSON()
Definition: ma_codec_json.cpp:25
EncoderJSON()
Definition: ma_codec_json.cpp:9
const size_t size() const override
Encoder type for get size.
Definition: ma_codec_json.cpp:151
ma_err_t reset() override
Reset the proto object.
Definition: ma_codec_json.cpp:155
Definition: ma_osal.h:80
Definition: ma_sensor.h:12
ma_msg_type_t
Definition: ma_types.h:252
ma_err_t
Definition: ma_types.h:21
Definition: ma_cv.cpp:7
Definition: ma_types.h:289
Definition: ma_types.h:314
Definition: ma_types.h:323
Definition: ma_types.h:138
Definition: ma_types.h:300