Files
c/kubernetes/model/object.c

52 lines
859 B
C
Raw Normal View History

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "object.h"
object_t *object_create() {
2022-06-14 10:38:10 +08:00
object_t *object = calloc(1, sizeof(object_t));
return object;
}
void object_free(object_t *object) {
2022-06-14 10:38:10 +08:00
if (!object) {
return ;
}
if (object->temporary) {
free(object->temporary);
object->temporary = NULL;
}
free (object);
}
cJSON *object_convertToJSON(object_t *object) {
2022-06-14 10:38:10 +08:00
if (!object) {
return NULL;
}
2022-06-14 10:38:10 +08:00
if (!object->temporary) {
return cJSON_Parse("null");
2022-06-14 10:38:10 +08:00
}
return cJSON_Parse(object->temporary);
}
2022-06-14 10:38:10 +08:00
object_t *object_parseFromJSON(cJSON *json){
if (!json) {
goto end;
}
2022-06-14 10:38:10 +08:00
object_t *object = object_create();
if (!object) {
goto end;
}
object->temporary = cJSON_Print(json);
return object;
2022-06-14 10:38:10 +08:00
end:
return NULL;
}