--- a/src/cx/json.h Fri Nov 01 16:21:06 2024 +0100 +++ b/src/cx/json.h Fri Nov 01 17:24:51 2024 +0100 @@ -69,7 +69,7 @@ CX_JSON_LITERAL }; -enum cx_json_literal_type { +enum cx_json_literal { CX_JSON_NULL, CX_JSON_TRUE, CX_JSON_FALSE @@ -88,7 +88,6 @@ typedef enum cx_json_token_type CxJsonTokenType; typedef enum cx_json_value_type CxJsonValueType; -typedef enum cx_json_literal_type CxJsonLiteralType; typedef enum cx_json_reader_type CxJsonReaderType; typedef struct cx_json_s CxJson; @@ -99,9 +98,9 @@ typedef struct cx_json_array_s CxJsonArray; typedef struct cx_json_object_s CxJsonObject; typedef struct cx_mutstr_s CxJsonString; -typedef struct cx_json_integer_s CxJsonInteger; -typedef struct cx_json_number_s CxJsonNumber; -typedef struct cx_json_literal_s CxJsonLiteral; +typedef int64_t CxJsonInteger; +typedef double CxJsonNumber; +typedef enum cx_json_literal CxJsonLiteral; typedef struct cx_json_obj_value_s CxJsonObjValue; @@ -163,20 +162,6 @@ CxJsonValue *value; }; -// TODO: remove single member structs - -struct cx_json_integer_s { - int64_t value; -}; - -struct cx_json_number_s { - double value; -}; - -struct cx_json_literal_s { - CxJsonLiteralType literal; -}; - struct cx_json_value_s { CxJsonValueType type; union { @@ -200,7 +185,6 @@ __attribute__((__nonnull__)) void cxJsonFill(CxJson *json, const char *buf, size_t len); -// TODO: discuss if it is intentional that cxJsonNext() will usually parse an entire file in one go __attribute__((__nonnull__)) int cxJsonNext(CxJson *json, CxJsonValue **value); @@ -239,22 +223,22 @@ __attribute__((__nonnull__)) static inline bool cxJsonIsBool(CxJsonValue *value) { - return cxJsonIsLiteral(value) && value->value.literal.literal != CX_JSON_NULL; + return cxJsonIsLiteral(value) && value->value.literal != CX_JSON_NULL; } __attribute__((__nonnull__)) static inline bool cxJsonIsTrue(CxJsonValue *value) { - return cxJsonIsLiteral(value) && value->value.literal.literal == CX_JSON_TRUE; + return cxJsonIsLiteral(value) && value->value.literal == CX_JSON_TRUE; } __attribute__((__nonnull__)) static inline bool cxJsonIsFalse(CxJsonValue *value) { - return cxJsonIsLiteral(value) && value->value.literal.literal == CX_JSON_FALSE; + return cxJsonIsLiteral(value) && value->value.literal == CX_JSON_FALSE; } __attribute__((__nonnull__)) static inline bool cxJsonIsNull(CxJsonValue *value) { - return cxJsonIsLiteral(value) && value->value.literal.literal == CX_JSON_NULL; + return cxJsonIsLiteral(value) && value->value.literal == CX_JSON_NULL; } __attribute__((__nonnull__)) @@ -265,17 +249,17 @@ __attribute__((__nonnull__)) static inline double cxJsonAsDouble(CxJsonValue *value) { - return value->value.number.value; + return value->value.number; } __attribute__((__nonnull__)) static inline int64_t cxJsonAsInteger(CxJsonValue *value) { - return value->value.integer.value; + return value->value.integer; } __attribute__((__nonnull__)) static inline bool cxJsonAsBool(CxJsonValue *value) { - return value->value.literal.literal == CX_JSON_TRUE; + return value->value.literal == CX_JSON_TRUE; } __attribute__((__nonnull__))