Beispiel #1
0
struct sr_ruby_frame *
sr_ruby_frame_from_json(struct sr_json_value *root, char **error_message)
{
    if (!JSON_CHECK_TYPE(root, SR_JSON_OBJECT, "frame"))
        return NULL;

    struct sr_ruby_frame *result = sr_ruby_frame_new();
    struct sr_json_value *val;

    /* Source file name */
    if ((val = json_element(root, "file_name")))
    {
        if (!JSON_CHECK_TYPE(val, SR_JSON_STRING, "file_name"))
            goto fail;

        result->file_name = sr_strdup(val->u.string.ptr);
    }

    /* Function name / special function. */
    if ((val = json_element(root, "function_name")))
    {
        if (!JSON_CHECK_TYPE(val, SR_JSON_STRING, "function_name"))
            goto fail;

        result->special_function = false;
        result->function_name = sr_strdup(val->u.string.ptr);
    }
    else if ((val = json_element(root, "special_function")))
    {
        if (!JSON_CHECK_TYPE(val, SR_JSON_STRING, "special_function"))
            goto fail;

        result->special_function = true;
        result->function_name = sr_strdup(val->u.string.ptr);
    }

    bool success =
        JSON_READ_UINT32(root, "file_line", &result->file_line) &&
        JSON_READ_UINT32(root, "block_level", &result->block_level) &&
        JSON_READ_UINT32(root, "rescue_level", &result->rescue_level);

    if (!success)
        goto fail;

    return result;

fail:
    sr_ruby_frame_free(result);
    return NULL;
}
Beispiel #2
0
struct sr_java_frame *
sr_java_frame_from_json(struct sr_json_value *root, char **error_message)
{
    if (!JSON_CHECK_TYPE(root, SR_JSON_OBJECT, "frame"))
        return NULL;

    struct sr_java_frame *result = sr_java_frame_new();

    bool success =
        JSON_READ_STRING(root, "name", &result->name) &&
        JSON_READ_STRING(root, "file_name", &result->file_name) &&
        JSON_READ_UINT32(root, "file_line", &result->file_line) &&
        JSON_READ_STRING(root, "class_path", &result->class_path) &&
        JSON_READ_BOOL(root, "is_native", &result->is_native) &&
        JSON_READ_BOOL(root, "is_exception", &result->is_exception) &&
        JSON_READ_STRING(root, "message", &result->message);

    if (!success)
    {
        sr_java_frame_free(result);
        return NULL;
    }

    return result;
}