ata-validator 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/ata_c.cpp ADDED
@@ -0,0 +1,63 @@
1
+ #include "ata_c.h"
2
+
3
+ #include "ata.h"
4
+
5
+ #include <string>
6
+ #include <vector>
7
+
8
+ // Thread-local storage for last validation errors
9
+ static thread_local std::vector<ata::validation_error> last_errors;
10
+
11
+ struct ata_schema_s {
12
+ ata::schema_ref ref;
13
+ };
14
+
15
+ ata_schema ata_compile(const char* schema_json, size_t length) {
16
+ auto ref = ata::compile(std::string_view(schema_json, length));
17
+ if (!ref) return nullptr;
18
+ auto* s = new (std::nothrow) ata_schema_s;
19
+ if (!s) return nullptr;
20
+ s->ref = std::move(ref);
21
+ return s;
22
+ }
23
+
24
+ void ata_schema_free(ata_schema schema) {
25
+ delete schema;
26
+ }
27
+
28
+ ata_result ata_validate(ata_schema schema, const char* json, size_t length) {
29
+ if (!schema) {
30
+ last_errors.clear();
31
+ return {false, 0};
32
+ }
33
+ auto result = ata::validate(schema->ref, std::string_view(json, length));
34
+ last_errors = std::move(result.errors);
35
+ return {result.valid, last_errors.size()};
36
+ }
37
+
38
+ ata_result ata_validate_oneshot(const char* schema_json, size_t schema_length,
39
+ const char* json, size_t json_length) {
40
+ auto result = ata::validate(std::string_view(schema_json, schema_length),
41
+ std::string_view(json, json_length));
42
+ last_errors = std::move(result.errors);
43
+ return {result.valid, last_errors.size()};
44
+ }
45
+
46
+ ata_string ata_get_error_message(size_t index) {
47
+ if (index >= last_errors.size()) return {nullptr, 0};
48
+ return {last_errors[index].message.c_str(),
49
+ last_errors[index].message.size()};
50
+ }
51
+
52
+ ata_string ata_get_error_path(size_t index) {
53
+ if (index >= last_errors.size()) return {nullptr, 0};
54
+ return {last_errors[index].path.c_str(), last_errors[index].path.size()};
55
+ }
56
+
57
+ const char* ata_get_version(void) {
58
+ return "0.1.0";
59
+ }
60
+
61
+ ata_version_components ata_get_version_components(void) {
62
+ return {ata::VERSION_MAJOR, ata::VERSION_MINOR, ata::VERSION_REVISION};
63
+ }