@@ -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+
8590void 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