json_t *bunser(const char *buf, const char *end, int *needed, json_error_t *jerr) { json_int_t ival; switch (buf[0]) { case BSER_INT8: case BSER_INT16: case BSER_INT32: case BSER_INT64: if (!bunser_int(buf, end - buf, needed, &ival)) { snprintf(jerr->text, sizeof(jerr->text), "invalid integer encoding"); return NULL; } return json_integer(ival); case BSER_STRING: { const char *start; json_int_t len; if (!bunser_string(buf, end - buf, needed, &start, &len)) { snprintf(jerr->text, sizeof(jerr->text), "invalid string encoding"); return NULL; } return json_string_binary(start, len); } case BSER_REAL: *needed = sizeof(double) + 1; return json_real(*(double*)(buf+1)); case BSER_TRUE: *needed = 1; return json_true(); case BSER_FALSE: *needed = 1; return json_false(); case BSER_NULL: *needed = 1; return json_null(); case BSER_ARRAY: return bunser_array(buf, end, needed, jerr); case BSER_TEMPLATE: return bunser_template(buf, end, needed, jerr); case BSER_OBJECT: return bunser_object(buf, end, needed, jerr); default: snprintf(jerr->text, sizeof(jerr->text), "invalid bser encoding type %02x", (int)buf[0]); return NULL; } return NULL; }
json_t *bunser(const char *buf, const char *end, json_int_t *needed, json_error_t *jerr) { json_int_t ival; switch (buf[0]) { case BSER_INT8: case BSER_INT16: case BSER_INT32: case BSER_INT64: if (!bunser_int(buf, end - buf, needed, &ival)) { snprintf(jerr->text, sizeof(jerr->text), "invalid integer encoding"); return NULL; } return json_integer(ival); case BSER_BYTESTRING: { const char *start; json_int_t len; if (!bunser_bytestring(buf, end - buf, needed, &start, &len)) { snprintf(jerr->text, sizeof(jerr->text), "invalid bytestring encoding"); return NULL; } return json_stringn_nocheck(start, len); } case BSER_REAL: { double dval; *needed = sizeof(double) + 1; memcpy(&dval, buf + 1, sizeof(dval)); return json_real(dval); } case BSER_TRUE: *needed = 1; return json_true(); case BSER_FALSE: *needed = 1; return json_false(); case BSER_NULL: *needed = 1; return json_null(); case BSER_ARRAY: return bunser_array(buf, end, needed, jerr); case BSER_TEMPLATE: return bunser_template(buf, end, needed, jerr); case BSER_OBJECT: return bunser_object(buf, end, needed, jerr); default: snprintf(jerr->text, sizeof(jerr->text), "invalid bser encoding type %02x", (int)buf[0]); return NULL; } #ifndef _WIN32 // It knows this is unreachable return NULL; #endif }