static json_object_to_json_string_fn json_object_boolean_to_json_string;
static json_object_to_json_string_fn json_object_double_to_json_string_default;
static json_object_to_json_string_fn json_object_int_to_json_string;
-static json_object_to_json_string_fn json_object_uint_to_json_string;
static json_object_to_json_string_fn json_object_string_to_json_string;
static json_object_to_json_string_fn json_object_array_to_json_string;
static json_object_to_json_string_fn _json_object_userdata_to_json_string;
case json_type_int:
jso->_to_json_string = &json_object_int_to_json_string;
break;
- case json_type_uint:
- jso->_to_json_string = &json_object_uint_to_json_string;
- break;
case json_type_object:
jso->_to_json_string = &json_object_object_to_json_string;
break;
case json_type_boolean:
return jso->o.c_boolean;
case json_type_int:
- return (jso->o.c_int64 != 0);
- case json_type_uint:
- return (jso->o.c_uint64 != 0);
+ switch(jso->o.c_int.cint_type) {
+ case json_object_int_type_int64:
+ return (jso->o.c_int.cint.c_int64 != 0);
+ case json_object_int_type_uint64:
+ return (jso->o.c_int.cint.c_uint64 != 0);
+ default:
+ return 0;
+ }
case json_type_double:
return (jso->o.c_double != 0);
case json_type_string:
{
/* room for 19 digits, the sign char, and a null term */
char sbuf[21];
- snprintf(sbuf, sizeof(sbuf), "%" PRId64, jso->o.c_int64);
- return printbuf_memappend (pb, sbuf, strlen(sbuf));
-}
-
-static int json_object_uint_to_json_string(struct json_object* jso,
- struct printbuf *pb,
- int level,
- int flags)
-{
- /* room for 20 digits, and a null term */
- char sbuf[21];
- snprintf(sbuf, sizeof(sbuf), "%" PRIu64, jso->o.c_uint64);
+ if (jso->o.c_int.cint_type == json_object_int_type_int64)
+ snprintf(sbuf, sizeof(sbuf), "%" PRId64, jso->o.c_int.cint.c_int64);
+ else if (jso->o.c_int.cint_type == json_object_int_type_uint64)
+ snprintf(sbuf, sizeof(sbuf), "%" PRIu64, jso->o.c_int.cint.c_uint64);
return printbuf_memappend (pb, sbuf, strlen(sbuf));
}
if (!jso)
return NULL;
jso->_to_json_string = &json_object_int_to_json_string;
- jso->o.c_int64 = i;
+ jso->o.c_int.cint.c_int64 = i;
+ jso->o.c_int.cint_type = json_object_int_type_int64;
return jso;
}
if(!jso) return 0;
o_type = jso->o_type;
- cint64 = jso->o.c_int64;
+ if (jso->o.c_int.cint_type == json_object_int_type_int64) {
+ cint64 = jso->o.c_int.cint.c_int64;
+ } else if (jso->o.c_int.cint_type == json_object_int_type_uint64) {
+ if (jso->o.c_int.cint.c_uint64 >= INT64_MAX)
+ cint64 = INT64_MAX;
+ cint64 = (int64_t)jso->o.c_int.cint.c_uint64;
+ }
if (o_type == json_type_string)
{
if (cint64 >= INT32_MAX)
return INT32_MAX;
return (int32_t) cint64;
- case json_type_uint:
- if (jso->o.c_uint64 >= INT32_MAX)
- return INT32_MAX;
- return (int32_t)jso->o.c_uint64;
case json_type_double:
if (jso->o.c_double <= INT32_MIN)
return INT32_MIN;
}
int json_object_set_int(struct json_object *jso,int new_value){
- if (!jso || jso->o_type!=json_type_int)
+ if (!jso || jso->o_type!=json_type_int || jso->o.c_int.cint_type != json_object_int_type_int64)
return 0;
- jso->o.c_int64=new_value;
+ jso->o.c_int.cint.c_int64=new_value;
return 1;
}
if (!jso)
return NULL;
jso->_to_json_string = &json_object_int_to_json_string;
- jso->o.c_int64 = i;
+ jso->o.c_int.cint.c_int64 = i;
+ jso->o.c_int.cint_type = json_object_int_type_int64;
return jso;
}
struct json_object* json_object_new_uint64(uint64_t i)
{
- struct json_object *jso = json_object_new(json_type_uint);
+ struct json_object *jso = json_object_new(json_type_int);
if (!jso)
return NULL;
- jso->_to_json_string = &json_object_uint_to_json_string;
- jso->o.c_uint64 = i;
+ jso->_to_json_string = &json_object_int_to_json_string;
+ jso->o.c_int.cint.c_uint64 = i;
+ jso->o.c_int.cint_type = json_object_int_type_uint64;
return jso;
}
switch(jso->o_type)
{
case json_type_int:
- return jso->o.c_int64;
- case json_type_uint:
- if (jso->o.c_uint64 >= INT64_MAX)
- return INT64_MAX;
- return (int64_t)jso->o.c_uint64;
+ switch(jso->o.c_int.cint_type) {
+ case json_object_int_type_int64:
+ return jso->o.c_int.cint.c_int64;
+ case json_object_int_type_uint64:
+ if (jso->o.c_int.cint.c_uint64 >= INT64_MAX)
+ return INT64_MAX;
+ return (int64_t)jso->o.c_int.cint.c_uint64;
+ default:
+ return 0;
+ }
case json_type_double:
// INT64_MAX can't be exactly represented as a double
// so cast to tell the compiler it's ok to round up.
switch(jso->o_type)
{
case json_type_int:
- if (jso->o.c_int64 < 0)
+ switch(jso->o.c_int.cint_type) {
+ case json_object_int_type_int64:
+ if (jso->o.c_int.cint.c_int64 < 0)
+ return 0;
+ return (uint64_t)jso->o.c_int.cint.c_int64;
+ case json_object_int_type_uint64:
+ return jso->o.c_int.cint.c_uint64;
+ default:
return 0;
- return (uint64_t)jso->o.c_int64;
- case json_type_uint:
- return jso->o.c_uint64;
+ }
case json_type_double:
// UINT64_MAX can't be exactly represented as a double
// so cast to tell the compiler it's ok to round up.
}
int json_object_set_int64(struct json_object *jso,int64_t new_value){
- if (!jso || jso->o_type!=json_type_int)
+ if (!jso || jso->o_type!=json_type_int || jso->o.c_int.cint_type != json_object_int_type_int64)
return 0;
- jso->o.c_int64=new_value;
+ jso->o.c_int.cint.c_int64=new_value;
return 1;
}
int json_object_set_uint64(struct json_object *jso,uint64_t new_value){
- if (!jso || jso->o_type!=json_type_uint)
+ if (!jso || jso->o_type!=json_type_int || jso->o.c_int.cint_type != json_object_int_type_uint64)
return 0;
- jso->o.c_uint64=new_value;
+ jso->o.c_int.cint.c_uint64=new_value;
return 1;
}
int json_object_int_inc(struct json_object *jso, int64_t val) {
- if (!jso || jso->o_type != json_type_int)
+ if (!jso || jso->o_type != json_type_int || jso->o.c_int.cint_type != json_object_int_type_int64)
return 0;
- if (val > 0 && jso->o.c_int64 > INT64_MAX - val) {
- jso->o.c_int64 = INT64_MAX;
- } else if (val < 0 && jso->o.c_int64 < INT64_MIN - val) {
- jso->o.c_int64 = INT64_MIN;
+ if (val > 0 && jso->o.c_int.cint.c_int64 > INT64_MAX - val) {
+ jso->o.c_int.cint.c_int64 = INT64_MAX;
+ } else if (val < 0 && jso->o.c_int.cint.c_int64 < INT64_MIN - val) {
+ jso->o.c_int.cint.c_int64 = INT64_MIN;
} else {
- jso->o.c_int64 += val;
+ jso->o.c_int.cint.c_int64 += val;
}
return 1;
}
int json_object_uint_inc(struct json_object *jso, uint64_t val) {
- if (!jso || jso->o_type != json_type_uint)
+ if (!jso || jso->o_type != json_type_int || jso->o.c_int.cint_type != json_object_int_type_uint64)
return 0;
- if (jso->o.c_uint64 > UINT64_MAX - val) {
- jso->o.c_uint64 = UINT64_MAX;
+ if (jso->o.c_int.cint.c_uint64 > UINT64_MAX - val) {
+ jso->o.c_int.cint.c_uint64 = UINT64_MAX;
} else {
- jso->o.c_uint64 += val;
+ jso->o.c_int.cint.c_uint64 += val;
}
return 1;
}
case json_type_double:
return jso->o.c_double;
case json_type_int:
- return jso->o.c_int64;
- case json_type_uint:
- return jso->o.c_uint64;
+ switch(jso->o.c_int.cint_type) {
+ case json_object_int_type_int64:
+ return jso->o.c_int.cint.c_int64;
+ case json_object_int_type_uint64:
+ return jso->o.c_int.cint.c_uint64;
+ default:
+ return 0.0;
+ }
case json_type_boolean:
return jso->o.c_boolean;
case json_type_string:
return (jso1->o.c_double == jso2->o.c_double);
case json_type_int:
- return (jso1->o.c_int64 == jso2->o.c_int64);
-
- case json_type_uint:
- return (jso1->o.c_uint64 == jso2->o.c_uint64);
+ if ((jso1->o.c_int.cint_type == json_object_int_type_int64)
+ && (jso2->o.c_int.cint_type == json_object_int_type_int64))
+ return (jso1->o.c_int.cint.c_int64 == jso2->o.c_int.cint.c_int64);
+ else if ((jso1->o.c_int.cint_type == json_object_int_type_uint64)
+ && (jso2->o.c_int.cint_type == json_object_int_type_uint64))
+ return (jso1->o.c_int.cint.c_uint64 == jso2->o.c_int.cint.c_uint64);
+ else
+ return 0;
case json_type_string:
return (jso1->o.c_string.len == jso2->o.c_string.len &&
break;
case json_type_int:
- *dst = json_object_new_int64(src->o.c_int64);
- break;
-
- case json_type_uint:
- *dst = json_object_new_uint64(src->o.c_uint64);
+ switch(src->o.c_int.cint_type) {
+ case json_object_int_type_int64:
+ *dst = json_object_new_int64(src->o.c_int.cint.c_int64);
+ break;
+ case json_object_int_type_uint64:
+ *dst = json_object_new_uint64(src->o.c_int.cint.c_uint64);
+ break;
+ }
break;
case json_type_string:
static void checktype_header()
{
- printf("json_object_is_type: %s,%s,%s,%s,%s,%s,%s,%s\n",
+ printf("json_object_is_type: %s,%s,%s,%s,%s,%s,%s\n",
json_type_to_name(json_type_null),
json_type_to_name(json_type_boolean),
json_type_to_name(json_type_double),
json_type_to_name(json_type_int),
- json_type_to_name(json_type_uint),
json_type_to_name(json_type_object),
json_type_to_name(json_type_array),
json_type_to_name(json_type_string));
if (field && !json_object_object_get_ex(new_obj, field, &o))
printf("Field %s does not exist\n", field);
- printf("new_obj%s%-18s: %d,%d,%d,%d,%d,%d,%d,%d\n",
+ printf("new_obj%s%-18s: %d,%d,%d,%d,%d,%d,%d\n",
field ? "." : " ", field ? field : "",
json_object_is_type(o, json_type_null),
json_object_is_type(o, json_type_boolean),
json_object_is_type(o, json_type_double),
json_object_is_type(o, json_type_int),
- json_object_is_type(o, json_type_uint),
json_object_is_type(o, json_type_object),
json_object_is_type(o, json_type_array),
json_object_is_type(o, json_type_string));
new_obj.a_null json_object_get_double()=0.000000
================================
-json_object_is_type: null,boolean,double,int,uint,object,array,string
-new_obj : 0,0,0,0,0,1,0,0
-new_obj.string_of_digits : 0,0,0,0,0,0,0,1
-new_obj.regular_number : 0,0,0,1,0,0,0,0
-new_obj.decimal_number : 0,0,1,0,0,0,0,0
-new_obj.boolean_true : 0,1,0,0,0,0,0,0
-new_obj.boolean_false : 0,1,0,0,0,0,0,0
-new_obj.int64_number : 0,0,0,1,0,0,0,0
-new_obj.negative_number : 0,0,0,1,0,0,0,0
-new_obj.a_null : 1,0,0,0,0,0,0,0
+json_object_is_type: null,boolean,double,int,object,array,string
+new_obj : 0,0,0,0,1,0,0
+new_obj.string_of_digits : 0,0,0,0,0,0,1
+new_obj.regular_number : 0,0,0,1,0,0,0
+new_obj.decimal_number : 0,0,1,0,0,0,0
+new_obj.boolean_true : 0,1,0,0,0,0,0
+new_obj.boolean_false : 0,1,0,0,0,0,0
+new_obj.int64_number : 0,0,0,1,0,0,0
+new_obj.negative_number : 0,0,0,1,0,0,0
+new_obj.a_null : 1,0,0,0,0,0,0