Delete the command field in read and write json

This commit is contained in:
gc87
2022-04-01 17:14:53 +08:00
parent 879c914f6c
commit 872620001c
3 changed files with 40 additions and 25 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ Pub And Recv
# try to receive a message with a matching UUID
${res} = Wait Until Keyword Succeeds 10s 0s Recv Message ${topic_res}
Should Be Equal As Strings ${res}[command] ${cmd}
# Should Be Equal As Strings ${res}[command] ${cmd}
# strip the `function` and `uuid` field
Remove From Dictionary ${res} uuid command
+10
View File
@@ -403,6 +403,16 @@ void command_response_handle(mqtt_response_t *response)
return;
}
if (0 != strcmp(mqtt->command, NEU_MQTT_CMD_GET) &&
0 != strcmp(mqtt->command, NEU_MQTT_CMD_SET) &&
0 != strcmp(mqtt->command, NEU_MQTT_CMD_ADD) &&
0 != strcmp(mqtt->command, NEU_MQTT_CMD_UPDATE) &&
0 != strcmp(mqtt->command, NEU_MQTT_CMD_DELETE) &&
0 != strcmp(mqtt->command, NEU_MQTT_CMD_NONE)) {
log_error("Unsupported command");
return;
}
switch (response->type) {
case TOPIC_TYPE_PING: {
// Ping
+29 -24
View File
@@ -31,27 +31,36 @@
int neu_json_decode_mqtt_req(char *buf, neu_json_mqtt_t **result)
{
int ret = 0;
int ret = 0;
neu_json_mqtt_t *req = calloc(1, sizeof(neu_json_mqtt_t));
neu_json_mqtt_t *req = calloc(1, sizeof(neu_json_mqtt_t));
neu_json_elem_t req_elems[] = { {
.name = "uuid",
.t = NEU_JSON_STR,
},
{
.name = "command",
.t = NEU_JSON_STR,
} };
ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(req_elems), req_elems);
if (ret != 0) {
neu_json_elem_t elems_uuid[] = { {
.name = "uuid",
.t = NEU_JSON_STR,
} };
neu_json_elem_t elems_command[] = { {
.name = "command",
.t = NEU_JSON_STR,
} };
ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elems_uuid), elems_uuid);
if (ret == 0) {
req->uuid = elems_uuid[0].v.val_str;
} else {
goto decode_fail;
}
req->uuid = req_elems[0].v.val_str;
req->command = req_elems[1].v.val_str;
ret =
neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elems_command), elems_command);
if (ret == 0) {
req->command = elems_command[0].v.val_str;
} else {
req->command = strdup("");
}
*result = req;
return ret;
return 0;
decode_fail:
if (req != NULL) {
@@ -83,15 +92,11 @@ int neu_json_encode_mqtt_resp(void *json_object, void *param)
neu_json_mqtt_t *resp = (neu_json_mqtt_t *) param;
neu_json_elem_t resp_elems[] = { {
.name = "uuid",
.t = NEU_JSON_STR,
.v.val_str = resp->uuid,
},
{
.name = "command",
.t = NEU_JSON_STR,
.v.val_str = resp->command,
} };
.name = "uuid",
.t = NEU_JSON_STR,
.v.val_str = resp->uuid,
} };
ret = neu_json_encode_field(json_object, resp_elems,
NEU_JSON_ELEM_SIZE(resp_elems));