static int json_parse_number(struct json_parser *parser, const char **value_r) { int ret; str_truncate(parser->value, 0); if ((ret = json_parse_int(parser)) <= 0) return ret; if (parser->data != parser->end && *parser->data == '.') { /* frac */ str_append_c(parser->value, *parser->data++); if ((ret = json_parse_digits(parser)) <= 0) return ret; } if (parser->data != parser->end && (*parser->data == 'e' || *parser->data == 'E')) { /* exp */ str_append_c(parser->value, *parser->data++); if (parser->data == parser->end) return 0; if (*parser->data == '+' || *parser->data == '-') str_append_c(parser->value, *parser->data++); if ((ret = json_parse_digits(parser)) <= 0) return ret; } if (parser->data == parser->end && !parser->input->eof) return 0; *value_r = str_c(parser->value); return 1; }
static int serial_opts_cb(const uint8_t **pp, const char *key, void *cb_data) { struct SerialOpts *opts = cb_data; long v; if (strcmp(key, "bitRate") == 0) { if (!json_parse_int(pp, &v)) { PRINTERR("Failed to parse bitRate value\n"); return 0; } opts->bitRate = v; } else if (strcmp(key, "bufferSize") == 0) { if (!json_parse_int(pp, &v)) { PRINTERR("Failed to parse bufferSize value\n"); return 0; } opts->bufferSize = v; } else if (strcmp(key, "ctsFlowControl") == 0) { if (!json_parse_int(pp, &v)) { PRINTERR("Failed to parse ctsFlowControl value\n"); return 0; } opts->ctsFlowControl = v; } else if (strcmp(key, "dataBits") == 0) { if (!json_parse_int(pp, &v)) { PRINTERR("Failed to parse dataBits value\n"); return 0; } opts->dataBits = v; } else if (strcmp(key, "parityBit") == 0) { if (!json_parse_int(pp, &v)) { PRINTERR("Failed to parse parityBit value\n"); return 0; } opts->parityBit = v; } else if (strcmp(key, "stopBits") == 0) { if (!json_parse_int(pp, &v)) { PRINTERR("Failed to parse stopBits value\n"); return 0; } opts->stopBits = v; } return 1; }