rj_schema 0.1.4 → 0.2.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.
- checksums.yaml +4 -4
- data/ext/rj_schema/extconf.rb +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +14 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/document.h +8 -20
- data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +29 -29
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +24 -11
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +1 -2
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +7 -2
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +5 -7
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +59 -38
- data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +1 -3
- data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +2 -8
- data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +12 -12
- data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +15 -13
- data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +27 -19
- data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +15 -6
- data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +4 -10
- data/ext/rj_schema/rapidjson/test/perftest/schematest.cpp +7 -0
- data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +12 -14
- data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +5 -0
- data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +2 -2
- data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +29 -0
- data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +303 -8
- data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +36 -2
- data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +2 -2
- data/ext/rj_schema/rj_schema.cpp +46 -26
- data/lib/rj_schema.rb +1 -1
- metadata +3 -3
@@ -109,8 +109,8 @@ struct ScanCopyUnescapedStringHandler : BaseReaderHandler<UTF8<>, ScanCopyUnesca
|
|
109
109
|
|
110
110
|
template <unsigned parseFlags, typename StreamType>
|
111
111
|
void TestScanCopyUnescapedString() {
|
112
|
-
char buffer[
|
113
|
-
char backup[
|
112
|
+
char buffer[1024u + 5 + 32];
|
113
|
+
char backup[1024u + 5 + 32];
|
114
114
|
|
115
115
|
// Test "ABCDABCD...\\"
|
116
116
|
for (size_t offset = 0; offset < 32; offset++) {
|
data/ext/rj_schema/rj_schema.cpp
CHANGED
@@ -18,25 +18,25 @@
|
|
18
18
|
#include <rapidjson/filereadstream.h>
|
19
19
|
#include <rapidjson/prettywriter.h>
|
20
20
|
|
21
|
+
typedef std::unordered_map<std::string, VALUE> SchemaInput;
|
21
22
|
typedef std::unordered_map<ID, rapidjson::SchemaDocument> SchemaCollection;
|
23
|
+
struct SchemaManager;
|
22
24
|
|
23
25
|
class SchemaDocumentProvider : public rapidjson::IRemoteSchemaDocumentProvider {
|
24
|
-
|
26
|
+
SchemaManager* schema_manager;
|
25
27
|
|
26
28
|
public:
|
27
|
-
SchemaDocumentProvider(
|
28
|
-
virtual const rapidjson::SchemaDocument* GetRemoteDocument(const char* uri, rapidjson::SizeType length)
|
29
|
-
auto it = schema_collection->find(rb_intern2(uri, length));
|
30
|
-
if (it == schema_collection->end())
|
31
|
-
throw std::invalid_argument(std::string("$ref remote schema not provided: ") + uri);
|
32
|
-
return &it->second;
|
33
|
-
}
|
29
|
+
SchemaDocumentProvider(SchemaManager* schema_manager) : schema_manager(schema_manager) { }
|
30
|
+
virtual const rapidjson::SchemaDocument* GetRemoteDocument(const char* uri, rapidjson::SizeType length);
|
34
31
|
};
|
35
32
|
|
36
33
|
struct SchemaManager {
|
34
|
+
SchemaInput input;
|
37
35
|
SchemaCollection collection;
|
38
36
|
SchemaDocumentProvider provider;
|
39
|
-
SchemaManager() : provider(
|
37
|
+
SchemaManager() : provider(this) { }
|
38
|
+
|
39
|
+
const rapidjson::SchemaDocument* provide(const char* uri, rapidjson::SizeType length);
|
40
40
|
};
|
41
41
|
|
42
42
|
rapidjson::Document parse_document(VALUE arg) {
|
@@ -57,6 +57,33 @@ rapidjson::Document parse_document(VALUE arg) {
|
|
57
57
|
return document;
|
58
58
|
}
|
59
59
|
|
60
|
+
const rapidjson::SchemaDocument* SchemaDocumentProvider::GetRemoteDocument(const char* uri, rapidjson::SizeType length) {
|
61
|
+
return schema_manager->provide(uri, length);
|
62
|
+
}
|
63
|
+
|
64
|
+
const rapidjson::SchemaDocument* SchemaManager::provide(const char* uri, rapidjson::SizeType length) {
|
65
|
+
auto collection_it = collection.find(rb_intern2(uri, length));
|
66
|
+
|
67
|
+
if (collection_it != collection.end())
|
68
|
+
return &collection_it->second;
|
69
|
+
|
70
|
+
auto input_it = input.find(std::string(uri, length));
|
71
|
+
|
72
|
+
if (input_it != input.end()) {
|
73
|
+
return &collection.emplace(
|
74
|
+
rb_intern2(uri, length),
|
75
|
+
rapidjson::SchemaDocument(
|
76
|
+
parse_document(input_it->second),
|
77
|
+
uri,
|
78
|
+
length,
|
79
|
+
&provider
|
80
|
+
)
|
81
|
+
).first->second;
|
82
|
+
}
|
83
|
+
|
84
|
+
throw std::invalid_argument(std::string("$ref remote schema not provided: ") + uri);
|
85
|
+
}
|
86
|
+
|
60
87
|
VALUE perform_validation(VALUE self, VALUE schema_arg, VALUE document_arg, bool with_errors) {
|
61
88
|
try {
|
62
89
|
SchemaManager* schema_manager;
|
@@ -117,23 +144,7 @@ extern "C" VALUE validator_alloc(VALUE self) {
|
|
117
144
|
}
|
118
145
|
|
119
146
|
extern "C" int validator_initialize_load_schema(VALUE key, VALUE value, VALUE input) {
|
120
|
-
|
121
|
-
|
122
|
-
try {
|
123
|
-
schema_manager->collection.emplace(
|
124
|
-
rb_to_id(key),
|
125
|
-
rapidjson::SchemaDocument(
|
126
|
-
parse_document(value),
|
127
|
-
StringValuePtr(key),
|
128
|
-
RSTRING_LEN(key),
|
129
|
-
&schema_manager->provider
|
130
|
-
)
|
131
|
-
);
|
132
|
-
}
|
133
|
-
catch (const std::invalid_argument& e) {
|
134
|
-
rb_raise(rb_eArgError, "%s", e.what());
|
135
|
-
}
|
136
|
-
|
147
|
+
reinterpret_cast<SchemaManager*>(input)->input.emplace(StringValueCStr(key), value);
|
137
148
|
return ST_CONTINUE;
|
138
149
|
}
|
139
150
|
|
@@ -146,6 +157,15 @@ extern "C" VALUE validator_initialize(int argc, VALUE* argv, VALUE self) {
|
|
146
157
|
|
147
158
|
rb_hash_foreach(argv[0], reinterpret_cast<int(*)(...)>(validator_initialize_load_schema), reinterpret_cast<VALUE>(schema_manager));
|
148
159
|
|
160
|
+
try {
|
161
|
+
for (const auto& schema : schema_manager->input) {
|
162
|
+
schema_manager->provide(schema.first.c_str(), schema.first.length());
|
163
|
+
}
|
164
|
+
}
|
165
|
+
catch (const std::invalid_argument& e) {
|
166
|
+
rb_raise(rb_eArgError, "%s", e.what());
|
167
|
+
}
|
168
|
+
|
149
169
|
return self;
|
150
170
|
}
|
151
171
|
|
data/lib/rj_schema.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rj_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Semmler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -737,7 +737,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
737
737
|
version: '0'
|
738
738
|
requirements: []
|
739
739
|
rubyforge_project:
|
740
|
-
rubygems_version: 2.7.
|
740
|
+
rubygems_version: 2.7.7
|
741
741
|
signing_key:
|
742
742
|
specification_version: 4
|
743
743
|
summary: JSON schema validation with RapidJSON
|