Skip to content

Commit 15f40e7

Browse files
committed
[update] add bson support
1 parent b405b82 commit 15f40e7

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

projects/llm_framework/main_camera/src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ class llm_task {
139139
}else if(devname_.find("axera_") != std::string::npos){
140140
hal_camera_open = axera_camera_open;
141141
hal_camera_close = axera_camera_close;
142+
}else {
143+
return true;
142144
}
143145
return false;
144146
}

projects/llm_framework/main_sys/include/zmq_bus.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ void zmq_com_send(int com_id, const std::string &out_str);
4242

4343
class zmq_bus_com {
4444
private:
45+
enum RAW_MSG_TYPE {
46+
RAW_NONE = 0,
47+
RAW_JSON = 1,
48+
RAW_BSON = 2,
49+
};
50+
4551
int reace_event_;
4652
int raw_msg_len_;
4753
std::string raw_msg_buff_;
@@ -63,6 +69,7 @@ class zmq_bus_com {
6369
void select_json_str(const std::string &json_src, std::function<void(const std::string &)> out_fun);
6470
virtual void on_data(const std::string &data);
6571
virtual void on_raw_data(const std::string &data);
72+
virtual void on_bson_data(const std::string &data);
6673
virtual void send_data(const std::string &data);
6774
virtual void reace_data_event();
6875
virtual void send_data_event();

projects/llm_framework/main_sys/src/zmq_bus.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ void zmq_bus_com::on_raw_data(const std::string &data)
8282
on_data(new_data);
8383
}
8484

85+
void zmq_bus_com::on_bson_data(const std::string &data)
86+
{
87+
// todo:..
88+
}
89+
8590
void zmq_bus_com::send_data(const std::string &data)
8691
{
8792
// printf("zmq_bus_com::send_data : send:%s\n", data.c_str());
@@ -173,7 +178,7 @@ void zmq_bus_com::select_json_str(const std::string &json_src, std::function<voi
173178
do {
174179
enloop = false;
175180
switch (reace_event_) {
176-
case 0: {
181+
case RAW_NONE: {
177182
json_str_.reserve(json_str_.length() + src_str->length());
178183
const char *data = src_str->c_str();
179184
for (int i = 0; i < src_str->length(); i++) {
@@ -203,14 +208,25 @@ void zmq_bus_com::select_json_str(const std::string &json_src, std::function<voi
203208
if ((json_str_.length() > 7) && (json_str_[1] == '\"') && (json_str_[2] == 'R') &&
204209
(json_str_[3] == 'A') && (json_str_[4] == 'W') && (json_str_[5] == '\"') &&
205210
(json_str_[6] == ':')) {
206-
reace_event_ = 10;
211+
reace_event_ = RAW_JSON;
207212
raw_msg_len_ = std::stoi(StackFlows::sample_json_str_get(json_str_, "RAW"));
208213
raw_msg_buff_.reserve(raw_msg_len_);
209214
if (json_src.length() > i) {
210215
src_str = std::make_shared<std::string>(src_str->substr(i + 1));
211216
enloop = true;
212217
}
213218
break;
219+
} else if ((json_str_.length() > 7) && (json_str_[1] == '\"') && (json_str_[2] == 'B') &&
220+
(json_str_[3] == 'O') && (json_str_[4] == 'N') && (json_str_[5] == '\"') &&
221+
(json_str_[6] == ':')) {
222+
reace_event_ = RAW_BSON;
223+
raw_msg_len_ = std::stoi(StackFlows::sample_json_str_get(json_str_, "BON"));
224+
raw_msg_buff_.reserve(raw_msg_len_);
225+
if (json_src.length() > i) {
226+
src_str = std::make_shared<std::string>(src_str->substr(i + 1));
227+
enloop = true;
228+
}
229+
break;
214230
}
215231
out_fun(json_str_);
216232
}
@@ -223,12 +239,12 @@ void zmq_bus_com::select_json_str(const std::string &json_src, std::function<voi
223239
}
224240
}
225241
} break;
226-
case 10: {
242+
case RAW_JSON: {
227243
if (raw_msg_len_ > src_str->length()) {
228244
raw_msg_buff_.append(src_str->c_str(), src_str->length());
229245
raw_msg_len_ -= src_str->length();
230246
} else {
231-
reace_event_ = 0;
247+
reace_event_ = RAW_NONE;
232248
raw_msg_buff_.append(src_str->c_str(), raw_msg_len_);
233249
on_raw_data(raw_msg_buff_);
234250
raw_msg_buff_.clear();
@@ -239,6 +255,22 @@ void zmq_bus_com::select_json_str(const std::string &json_src, std::function<voi
239255
}
240256
}
241257
} break;
258+
case RAW_BSON: {
259+
if (raw_msg_len_ > src_str->length()) {
260+
raw_msg_buff_.append(src_str->c_str(), src_str->length());
261+
raw_msg_len_ -= src_str->length();
262+
} else {
263+
reace_event_ = RAW_NONE;
264+
raw_msg_buff_.append(src_str->c_str(), raw_msg_len_);
265+
on_bson_data(raw_msg_buff_);
266+
raw_msg_buff_.clear();
267+
json_str_.clear();
268+
if (src_str->length() > raw_msg_len_) {
269+
src_str = std::make_shared<std::string>(src_str->substr(raw_msg_len_ + 1));
270+
enloop = true;
271+
}
272+
}
273+
} break;
242274
default:
243275
break;
244276
}

0 commit comments

Comments
 (0)