uint32_t get_API_uint(cJSON *obj,uint32_t val) { struct destbuf buf; if ( obj != 0 ) { if ( is_cJSON_Number(obj) != 0 ) return((uint32_t)obj->valuedouble); copy_cJSON(&buf,obj); val = atoi(buf.buf); } return(val); }
double get_API_float(cJSON *obj) { double val = 0.; struct destbuf buf; if ( obj != 0 ) { if ( is_cJSON_Number(obj) != 0 ) return(obj->valuedouble); copy_cJSON(&buf,obj); val = atof(buf.buf); } return(val); }
uint64_t get_API_nxt64bits(cJSON *obj) { uint64_t nxt64bits = 0; struct destbuf tmp; if ( obj != 0 ) { if ( is_cJSON_Number(obj) != 0 ) return((uint64_t)obj->valuedouble); copy_cJSON(&tmp,obj); nxt64bits = calc_nxt64bits(tmp.buf); } return(nxt64bits); }
int32_t get_API_int(cJSON *obj,int32_t val) { struct destbuf buf; if ( obj != 0 ) { if ( is_cJSON_Number(obj) != 0 ) return((int32_t)obj->valuedouble); copy_cJSON(&buf,obj); val = myatoi(buf.buf,0); if ( val < 0 ) val = 0; } return(val); }
int32_t jnum(cJSON *obj,char *field) { char *str; int32_t polarity = 1; if ( field != 0 ) obj = jobj(obj,field); if ( obj != 0 ) { if ( is_cJSON_Number(obj) != 0 ) return(obj->valuedouble); else if ( is_cJSON_String(obj) != 0 && (str= jstr(obj,0)) != 0 ) { if ( str[0] == '-' ) polarity = -1, str++; return(polarity * (int32_t)calc_nxt64bits(str)); } } return(0); }