Created
March 17, 2020 11:05
-
-
Save Angeall/bcf883d22ec35b8bed1292e0eed17c0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include "dummy_object.h" | |
char* dummydummy_object_ToString(dummy_api_dummy_object__e dummy) { | |
char* dummyArray[] = { "NULL", "Test1", "Test2", "Test3" }; | |
return dummyArray[dummy]; | |
} | |
dummy_api_dummy_object__e dummydummy_object_FromString(char* dummy){ | |
int stringToReturn = 0; | |
char *dummyArray[] = { "NULL", "Test1", "Test2", "Test3" }; | |
size_t sizeofArray = sizeof(dummyArray) / sizeof(dummyArray[0]); | |
while(stringToReturn < sizeofArray) { | |
if(strcmp(dummy, dummyArray[stringToReturn]) == 0) { | |
return stringToReturn; | |
} | |
stringToReturn++; | |
} | |
return 0; | |
} | |
dummy_object_t *dummy_object_create( | |
char *message, | |
) { | |
dummy_object_t *dummy_object_local_var = malloc(sizeof(dummy_object_t)); | |
if (!dummy_object_local_var) { | |
return NULL; | |
} | |
dummy_object_local_var->message = message; | |
dummy_object_local_var->dummy = dummy; | |
return dummy_object_local_var; | |
} | |
void dummy_object_free(dummy_object_t *dummy_object) { | |
listEntry_t *listEntry; | |
free(dummy_object->message); | |
free(dummy_object); | |
} | |
cJSON *dummy_object_convertToJSON(dummy_object_t *dummy_object) { | |
cJSON *item = cJSON_CreateObject(); | |
// dummy_object->message | |
if(dummy_object->message) { | |
if(cJSON_AddStringToObject(item, "message", dummy_object->message) == NULL) { | |
goto fail; //String | |
} | |
} | |
// dummy_object->dummy | |
return item; | |
fail: | |
if (item) { | |
cJSON_Delete(item); | |
} | |
return NULL; | |
} | |
dummy_object_t *dummy_object_parseFromJSON(cJSON *dummy_objectJSON){ | |
dummy_object_t *dummy_object_local_var = NULL; | |
// dummy_object->message | |
cJSON *message = cJSON_GetObjectItemCaseSensitive(dummy_objectJSON, "message"); | |
if (message) { | |
if(!cJSON_IsString(message)) | |
{ | |
goto end; //String | |
} | |
} | |
// dummy_object->dummy | |
cJSON *dummy = cJSON_GetObjectItemCaseSensitive(dummy_objectJSON, "dummy"); | |
} | |
dummy_object_local_var = dummy_object_create ( | |
message ? strdup(message->valuestring) : NULL, | |
); | |
return dummy_object_local_var; | |
end: | |
return NULL; | |
} |
Author
Angeall
commented
Mar 17, 2020
- Line 33: error with element dummy not present in header
- Line 83: one bracket too much that closes the function declaration too early
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment