-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
UPDATE: Current plans are described here
In #175 (comment) I was discussing the need for a way to configure cJSON that doesn't require changing or extending the API when a new option is added and doesn't break the ABI either.
This is just an idea and I would like to get some feedback on this.
Since cJSON is a JSON library, using JSON for configuration seems sensible, not as string but rather as tree of cJSON structs.
Traversing the tree of items every time a configuration option is accessed would be a big overhead, so I think there should be a function like cJSON_CreateConfiguration or similar that takes a tree of cJSON structs and returns a dynamically allocated struct that can then be passed to cJSONs functions.
Like the following:
cJSON *configuration_json = cJSON_CreateObject();
cJSON_AddItemToObject(configuration_json, "format", cJSON_CreateBool(0));
/* hooks are of type cJSON_Hooks */
cJSON_Configuration *configuration = cJSON_CreateConfiguration(configuration_json, hooks);
/* this prints the configuration_json without formatting */
char *printed_configuration = cJSON_PrintWithConfiguration(configuration_json, configuration); cJSON_Configuration would just be a typedef of void*. The internal representation can be changed from version to version without breaking compatibility.
What do you think?