| | |
| | | #include "3rdparty/bus_client/cbhomeclient.h" |
| | | #include "3rdparty/bus_client/message.h" |
| | | #include "proto/x86_64/sysset.pb.h" |
| | | #include <vector> |
| | | |
| | | using namespace protomsg; |
| | | using namespace std; |
| | |
| | | return json; |
| | | } |
| | | |
| | | extern "C" int bus_dbapi_get_json_data(const char * json, char ** pptr_data) |
| | | extern "C" int bus_dbapi_get_json_data(const char * json, char ** pptr_data, yyjson_type *ptr_type) |
| | | { |
| | | /*{ |
| | | "success": true, |
| | |
| | | |
| | | // Get root["data"] |
| | | //yyjson_val *msg = yyjson_obj_get(root, "data"); |
| | | yyjson_val *data = yyjson_obj_get(root, "data"); |
| | | yyjson_val *data = yyjson_obj_get(root, "data"); |
| | | |
| | | *ptr_type = yyjson_get_type(data); |
| | | ptr_value = yyjson_val_write(data, YYJSON_WRITE_NOFLAG, &data_len); |
| | | printf("data: %s\n", ptr_value); |
| | | printf("len: %lu\n", data_len); |
| | |
| | | return ret; |
| | | } |
| | | |
| | | bool bus_dbapi_get_topic_data(void *handle, const char* topic, crepmsg **pptr_repmsg, size_t len) |
| | | { |
| | | const auto topicl = strlen(topic); |
| | | auto reqData = make_get_request(topic); |
| | | auto reqmsg = make_req_msg(topic, topicl, reqData, strlen(reqData)); |
| | | |
| | | if (bus_client_request(handle, reqmsg, pptr_repmsg)) { |
| | | printf("======>> bus_client_reqest [%s] get [%s]\n", topic, (*pptr_repmsg)->data); |
| | | } else { |
| | | return false; |
| | | } |
| | | |
| | | len = strlen((*pptr_repmsg)->data) + 1; |
| | | |
| | | free(reqData); |
| | | } |
| | | |
| | | |
| | | bool bus_dbapi_get(void *handle, const char* topic, google::protobuf::Message& message) { |
| | | const auto topicl = strlen(topic); |
| | | |
| | | auto reqData = make_get_request(topic); |
| | | |
| | | auto reqmsg = make_req_msg(topic, topicl, reqData, strlen(reqData)); |
| | | |
| | | crepmsg *repmsg = NULL; |
| | | if (bus_client_request(handle, reqmsg, &repmsg)) { |
| | | printf("======>> bus_client_reqest [%s] get [%s]\n", topic, repmsg->data); |
| | | } else { |
| | | return false; |
| | | } |
| | | yyjson_type type = YYJSON_TYPE_OBJ; |
| | | crepmsg *repmsg = NULL; |
| | | size_t len = 0; |
| | | |
| | | bus_dbapi_get_topic_data(handle, topic, &repmsg, len); |
| | | |
| | | int msglen = strlen(repmsg->data); |
| | | char* msgdata = (char *)malloc(msglen); |
| | | memset(msgdata, 0 , msglen); |
| | | |
| | | if(0 == bus_dbapi_get_json_data((const char *)repmsg->data, &msgdata)) |
| | | if(0 == bus_dbapi_get_json_data((const char *)repmsg->data, &msgdata, &type)) |
| | | { |
| | | printf("======>> protomsg: %s\n", msgdata); |
| | | std::string jsonString = msgdata; |
| | | if (json_to_proto(jsonString, message)) |
| | | { |
| | | printf("======>> json_to_proto done\n"); |
| | | } |
| | | else |
| | | { |
| | | printf("======>> json_to_proto fail\n"); |
| | | return false; |
| | | } |
| | | printf("======>> protomsg: %s\n", msgdata); |
| | | } |
| | | |
| | | std::string jsonString = msgdata; |
| | | if (json_to_proto(jsonString, message)) |
| | | { |
| | | printf("======>> json_to_proto done\n"); |
| | | } |
| | | else |
| | | { |
| | | printf("======>> json_to_proto fail\n"); |
| | | return false; |
| | | } |
| | | |
| | | free(msgdata); |
| | | free_reqmsg(reqmsg); |
| | | free(reqData); |
| | | free_reply_msg(repmsg); |
| | | |
| | | return true; |
| | | } |
| | | |