in watchman/bser.cpp [675:743]
json_ref 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 nullptr;
}
return json_integer(ival);
case BSER_BYTESTRING:
case BSER_UTF8STRING: {
const char* start;
json_int_t len;
if (!bunser_generic_string(buf, end - buf, needed, &start, &len)) {
snprintf(jerr->text, sizeof(jerr->text), "invalid bytestring encoding");
return nullptr;
}
return typed_string_to_json(
start,
len,
buf[0] == BSER_BYTESTRING ? W_STRING_BYTE : W_STRING_UNICODE);
}
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 nullptr;
}
#ifndef _WIN32 // It knows this is unreachable
return nullptr;
#endif
}