| | |
| | | #include "google/protobuf/dynamic_message.h" |
| | | #include "google/protobuf/compiler/importer.h" |
| | | |
| | | #include "3dparty/yyjson/yyjson.h" |
| | | #include "3rdparty/yyjson/yyjson.h" |
| | | |
| | | #include "bhome_msg_api.pb.h" |
| | | using namespace bhome_msg; |
| | |
| | | char* entry = NULL; |
| | | size_t entry_size = 0; |
| | | json2str(sv, &entry, &entry_size); |
| | | arr[i] = ptrT<char>(entry_size+1); |
| | | memcpy(arr[i], entry, entry_size); |
| | | arr[i] = entry; |
| | | } |
| | | return make_tuple(arr, count); |
| | | }; |
| | |
| | | tie(msg->procid, msg->procidl) = copymemory(pid, pids); |
| | | |
| | | MsgRequestTopic msgRT; |
| | | if (!msgRT.ParseFromArray(data, size)) return NULL; |
| | | if (!msgRT.ParseFromArray(data, size)) { |
| | | free(msg->procid); |
| | | free(msg); |
| | | return NULL; |
| | | } |
| | | tie(msg->msg, msg->msgl) = copymemory(msgRT.data()); |
| | | |
| | | return msg; |
| | |
| | | msgRT.set_topic(topic, topicl); |
| | | msgRT.set_data(data, datal); |
| | | |
| | | auto pbstr = msgRT.SerializeAsString(); |
| | | const auto& pbstr = msgRT.SerializeAsString(); |
| | | tie(msg->msg, msg->msgl) = copymemory(pbstr); |
| | | auto doc = yyjson_read(msg->msg, msg->msgl, 0); |
| | | yyjson_val* root = yyjson_doc_get_root(doc); |
| | | |
| | | auto obj = [](yyjson_val* v, const char* name){return yyjson_obj_get(v, name);}; |
| | | |
| | | auto jp = obj(root, "path"); |
| | | auto jb = obj(root, "body"); |
| | | if (jp && jb){ |
| | | tie(msg->path, msg->pathl) = copymemory(yyjson_get_str(jp), yyjson_get_len(jp)); |
| | | tie(msg->body, msg->bodyl) = copymemory(yyjson_get_str(jb), yyjson_get_len(jb)); |
| | | } |
| | | |
| | | yyjson_doc_free(doc); |
| | | |
| | | return msg; |
| | | } |
| | |
| | | if (msg){ |
| | | free(msg->procid); |
| | | free(msg->msg); |
| | | free(msg->path); |
| | | free(msg->body); |
| | | free(msg); |
| | | } |
| | | } |
| | | |
| | | static tuple<const char*, size_t> json2body(yyjson_doc* doc){ |
| | | ignoreT(json2body); |
| | | |
| | | yyjson_val* root = yyjson_doc_get_root(doc); |
| | | |
| | | auto obj = [](yyjson_val* v, const char* name){return yyjson_obj_get(v, name);}; |
| | |
| | | if (!jp) return make_tuple((const char*)NULL, 0); |
| | | auto jb = obj(root, "body"); |
| | | if (!jb) return make_tuple((const char*)NULL, 0); |
| | | return make_tuple(yyjson_get_str(jb), yyjson_get_len(jp)); |
| | | return make_tuple(yyjson_get_str(jb), yyjson_get_len(jb)); |
| | | } |
| | | |
| | | struct cstackmsgerr* get_reqmsg_stackerr(struct creqmsg* msg){ |
| | | auto doc0 = yyjson_read(msg->msg, msg->msgl, 0); |
| | | auto tpbody = json2body(doc0); |
| | | if (!get<0>(tpbody)) return NULL; |
| | | // auto doc0 = yyjson_read(msg->msg, msg->msgl, 0); |
| | | // auto tpbody = json2body(doc0); |
| | | // if (!get<0>(tpbody)) return NULL; |
| | | // auto doc = yyjson_read(get<0>(tpbody), get<1>(tpbody), 0); |
| | | |
| | | auto doc = yyjson_read(get<0>(tpbody), get<1>(tpbody), 0); |
| | | auto doc = yyjson_read(msg->body, msg->bodyl, 0); |
| | | auto root = yyjson_doc_get_root(doc); |
| | | |
| | | auto obj = [](yyjson_val* v, const char* name){return yyjson_obj_get(v, name);}; |
| | |
| | | tie(smsg->fileid, smsg->fileidl) = copymemory(yyjson_get_str(jfid), yyjson_get_len(jfid)); |
| | | yyjson_doc_free(doc); |
| | | |
| | | yyjson_doc_free(doc0); |
| | | // yyjson_doc_free(doc0); |
| | | |
| | | return smsg; |
| | | } |
| | |
| | | } |
| | | // decode success msg |
| | | struct cstackmsg* get_reqmsg_stack(struct creqmsg* msg){ |
| | | auto doc0 = yyjson_read(msg->msg, msg->msgl, 0); |
| | | auto tpbody = json2body(doc0); |
| | | if (!get<0>(tpbody)) return NULL; |
| | | // auto doc0 = yyjson_read(msg->msg, msg->msgl, 0); |
| | | // auto tpbody = json2body(doc0); |
| | | // if (!get<0>(tpbody)) return NULL; |
| | | // auto doc = yyjson_read(get<0>(tpbody), get<1>(tpbody), 0); |
| | | |
| | | auto doc = yyjson_read(get<0>(tpbody), get<1>(tpbody), 0); |
| | | auto doc = yyjson_read(msg->body, msg->bodyl, 0); |
| | | auto root = yyjson_doc_get_root(doc); |
| | | |
| | | auto obj = [](yyjson_val* v, const char* name){return yyjson_obj_get(v, name);}; |
| | |
| | | smsg->files[i] = file; |
| | | } |
| | | yyjson_doc_free(doc); |
| | | yyjson_doc_free(doc0); |
| | | // yyjson_doc_free(doc0); |
| | | |
| | | return smsg; |
| | | } |
| | |
| | | yyjson_mut_doc_free(doc); |
| | | return cstr_ref(json, jsonl); |
| | | } |
| | | |
| | | void free_query_procs(struct cqueryprocs* procs, const size_t count){ |
| | | for(size_t i = 0; i < count; i++){ |
| | | free(procs[i].id); |
| | | } |
| | | free(procs); |
| | | } |