Skip to content

Commit b34dcb3

Browse files
committed
[update] SDK && add bson
1 parent 476b3ad commit b34dcb3

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

SDK

Submodule SDK updated 36 files

projects/llm_framework/main_sys/SConstruct

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ LDFLAGS = []
1717
LINK_SEARCH_PATH = []
1818
STATIC_FILES = []
1919

20+
if 'CONFIG_LIBBSON_ENABLED' in os.environ:
21+
REQUIREMENTS += ['bson']
22+
DEFINITIONS += ['-DENABLE_BSON']
23+
2024
# DEFINITIONS += ['-std=c++17']
2125

2226
# REQUIREMENTS += ['Backward_cpp']

projects/llm_framework/main_sys/src/zmq_bus.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include <arm_neon.h>
1616
#endif
1717

18+
#ifdef ENABLE_BSON
19+
#include <bson/bson.h>
20+
#endif
21+
1822
using namespace StackFlows;
1923

2024
void unit_action_match(int com_id, const std::string &json_str);
@@ -84,7 +88,25 @@ void zmq_bus_com::on_raw_data(const std::string &data)
8488

8589
void zmq_bus_com::on_bson_data(const std::string &data)
8690
{
87-
// todo:..
91+
#ifdef ENABLE_BSON
92+
bson_t *bson = bson_new_from_data((const uint8_t *)data.c_str(), data.length());
93+
if (!bson) {
94+
SLOGW("bson is error");
95+
return ;
96+
}
97+
char *json = bson_as_canonical_extended_json(bson, NULL);
98+
if (!json) {
99+
SLOGW("bson to json error");
100+
bson_destroy(bson);
101+
return ;
102+
}
103+
std::string new_data(json);
104+
on_data(new_data);
105+
bson_free(json);
106+
bson_destroy(bson);
107+
#else
108+
SLOGW("bson not enable");
109+
#endif
88110
}
89111

90112
void zmq_bus_com::send_data(const std::string &data)

0 commit comments

Comments
 (0)