Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.7.0+

Validate a QR Code Request

See more QR Code Examples

Demonstrates the validate operation, which examines a request without producing anything. The scope says how far to look: definition checks the options, capacity also checks that the data fits a QR symbol, and layout also checks the rendered size against the limits. The response has a validationStatus of valid or invalid, a list of checks, and findings[] describing what is wrong. A request that cannot be understood at all, such as one with a misspelled option, still makes the call fail in the usual way.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let fmt = chilkat::Formats::new();
let json_out = chilkat::JsonObject::new();
let mut n: i32 = 0;

let json = chilkat::JsonObject::new();
let _ = json.update_string("target", "symbol");
let _ = json.update_string("validation.scope", "capacity");
let _ = json.update_string("payload.text", "https://www.chilkatsoft.com/barcode_overview.asp");

if fmt.qr_code("validate", &json, &json_out).is_err() {
    println!("{}", fmt.last_error_text());
    return;
}

println!("status: {}", json_out.string_of("validationStatus").unwrap_or_default());
n = json_out.size_of_array("checks");
for i in 0..n {
    json_out.set_i(i);
    println!("  {}: {}", json_out.string_of("checks[i].name").unwrap_or_default(), json_out.string_of("checks[i].status").unwrap_or_default());
}

// The same text does not fit version 2 at error-correction level H.
let _ = json.update_int("encoding.qr.maxVersion", 2);
let _ = json.update_string("encoding.qr.errorCorrection", "H");

if fmt.qr_code("validate", &json, &json_out).is_err() {
    println!("{}", fmt.last_error_text());
    return;
}

println!("status: {}", json_out.string_of("validationStatus").unwrap_or_default());
n = json_out.size_of_array("checks");
for i in 0..n {
    json_out.set_i(i);
    println!("  {}: {}", json_out.string_of("checks[i].name").unwrap_or_default(), json_out.string_of("checks[i].status").unwrap_or_default());
}

n = json_out.size_of_array("findings");
for i in 0..n {
    json_out.set_i(i);
    println!("finding: {} at {}", json_out.string_of("findings[i].code").unwrap_or_default(), json_out.string_of("findings[i].path").unwrap_or_default());
    println!("  {}", json_out.string_of("findings[i].message").unwrap_or_default());
}

// Sample output:

// status: valid
//   definition: passed
//   capacity: passed
//   layout: notApplicable
// status: invalid
//   definition: passed
//   capacity: failed
//   layout: notApplicable
// finding: capacityExceeded at /payload
//   the payload does not fit any admitted QR version at the selected error-correction level