Changeset 8563fe7 for lib/parson.h


Ignore:
Timestamp:
2015-05-05T22:39:39Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
f81d8b8
Parents:
5726a0d
Message:

Make my fork of parson non-JSON-compliant. I don't care that JavaScript's
tiny little brain doesn't comprehend integers and wants everything to be a
float, the adults need integers now. Big integers. So add them, just like
the old js lib did. This also lets me clean up some horrible things in the
RPC module.

Try to have behaviour similar to the old lib: Throw as much as possible into
an integer, only switch to double when there's a non-int or a number larger
than what fits a "signed long long".

Yes this is horrible, and no I don't think the parson upstreams will accept
this. But the alternative is to stay compliant to an accidentally popular
data interchange format based on accidentally popular joke language and do
a lot of manual string-to-int64 parsing in the Twitter codebase. How about
NOPE.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/parson.h

    r5726a0d r8563fe7  
    3737typedef struct json_value_t  JSON_Value;
    3838
     39typedef long long jint;
     40
    3941enum json_value_type {
    4042    JSONError   = -1,
    4143    JSONNull    = 1,
    4244    JSONString  = 2,
     45    JSONInteger = 7,
    4346    JSONNumber  = 3,
    4447    JSONObject  = 4,
     
    100103JSON_Object * json_object_get_object (const JSON_Object *object, const char *name);
    101104JSON_Array  * json_object_get_array  (const JSON_Object *object, const char *name);
     105jint          json_object_get_integer(const JSON_Object *object, const char *name); /* returns 0 on fail */
    102106double        json_object_get_number (const JSON_Object *object, const char *name); /* returns 0 on fail */
    103107int           json_object_get_boolean(const JSON_Object *object, const char *name); /* returns -1 on fail */
     
    111115JSON_Object * json_object_dotget_object (const JSON_Object *object, const char *name);
    112116JSON_Array  * json_object_dotget_array  (const JSON_Object *object, const char *name);
     117jint          json_object_dotget_integer(const JSON_Object *object, const char *name); /* returns 0 on fail */
    113118double        json_object_dotget_number (const JSON_Object *object, const char *name); /* returns 0 on fail */
    114119int           json_object_dotget_boolean(const JSON_Object *object, const char *name); /* returns -1 on fail */
     
    123128JSON_Status json_object_set_value(JSON_Object *object, const char *name, JSON_Value *value);
    124129JSON_Status json_object_set_string(JSON_Object *object, const char *name, const char *string);
     130JSON_Status json_object_set_integer(JSON_Object *object, const char *name, jint number);
    125131JSON_Status json_object_set_number(JSON_Object *object, const char *name, double number);
    126132JSON_Status json_object_set_boolean(JSON_Object *object, const char *name, int boolean);
     
    130136JSON_Status json_object_dotset_value(JSON_Object *object, const char *name, JSON_Value *value);
    131137JSON_Status json_object_dotset_string(JSON_Object *object, const char *name, const char *string);
     138JSON_Status json_object_dotset_integer(JSON_Object *object, const char *name, jint number);
    132139JSON_Status json_object_dotset_number(JSON_Object *object, const char *name, double number);
    133140JSON_Status json_object_dotset_boolean(JSON_Object *object, const char *name, int boolean);
     
    150157JSON_Object * json_array_get_object (const JSON_Array *array, size_t index);
    151158JSON_Array  * json_array_get_array  (const JSON_Array *array, size_t index);
     159jint          json_array_get_integer(const JSON_Array *array, size_t index); /* returns 0 on fail */
    152160double        json_array_get_number (const JSON_Array *array, size_t index); /* returns 0 on fail */
    153161int           json_array_get_boolean(const JSON_Array *array, size_t index); /* returns -1 on fail */
     
    162170JSON_Status json_array_replace_value(JSON_Array *array, size_t i, JSON_Value *value);
    163171JSON_Status json_array_replace_string(JSON_Array *array, size_t i, const char* string);
     172JSON_Status json_array_replace_integer(JSON_Array *array, size_t i, jint number);
    164173JSON_Status json_array_replace_number(JSON_Array *array, size_t i, double number);
    165174JSON_Status json_array_replace_boolean(JSON_Array *array, size_t i, int boolean);
     
    172181JSON_Status json_array_append_value(JSON_Array *array, JSON_Value *value);
    173182JSON_Status json_array_append_string(JSON_Array *array, const char *string);
     183JSON_Status json_array_append_integer(JSON_Array *array, jint number);
    174184JSON_Status json_array_append_number(JSON_Array *array, double number);
    175185JSON_Status json_array_append_boolean(JSON_Array *array, int boolean);
     
    182192JSON_Value * json_value_init_array  (void);
    183193JSON_Value * json_value_init_string (const char *string); /* copies passed string */
     194JSON_Value * json_value_init_integer(jint number);
    184195JSON_Value * json_value_init_number (double number);
    185196JSON_Value * json_value_init_boolean(int boolean);
     
    192203JSON_Array  *   json_value_get_array  (const JSON_Value *value);
    193204const char  *   json_value_get_string (const JSON_Value *value);
     205jint            json_value_get_integer(const JSON_Value *value);
    194206double          json_value_get_number (const JSON_Value *value);
    195207int             json_value_get_boolean(const JSON_Value *value);
     
    200212JSON_Array  *   json_array  (const JSON_Value *value);
    201213const char  *   json_string (const JSON_Value *value);
     214jint            json_integer(const JSON_Value *value);
    202215double          json_number (const JSON_Value *value);
    203216int             json_boolean(const JSON_Value *value);
Note: See TracChangeset for help on using the changeset viewer.