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 }
json_t *w_string_to_json(w_string_t *str) { return json_stringn_nocheck(str->buf, str->len); }
/* -------------------------------------------------------------------------------------------- * String constructor. */ JValue(CSStr val, std::size_t len, bool check = true) : m_Ptr(check ? json_stringn(val, len) : json_stringn_nocheck(val,len)) { /* ... */ }