-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinteger_bounded_multiplier_8_bit.h
More file actions
49 lines (45 loc) · 2.15 KB
/
Copy pathinteger_bounded_multiplier_8_bit.h
File metadata and controls
49 lines (45 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class IntegerBoundedMultiplier8Bit final
: public sourcemeta::blaze::SchemaTransformRule {
public:
using mutates = std::true_type;
using reframe_after_transform = std::true_type;
IntegerBoundedMultiplier8Bit()
: sourcemeta::blaze::SchemaTransformRule{
"integer_bounded_multiplier_8_bit", ""} {};
[[nodiscard]] auto
condition(const sourcemeta::core::JSON &schema,
const sourcemeta::core::JSON &,
const sourcemeta::core::Vocabularies &vocabularies,
const sourcemeta::core::SchemaFrame &,
const sourcemeta::core::SchemaFrame::Location &location,
const sourcemeta::core::SchemaWalker &,
const sourcemeta::core::SchemaResolver &) const
-> sourcemeta::blaze::SchemaTransformRule::Result override {
if (location.dialect != "https://json-schema.org/draft/2020-12/schema" ||
!vocabularies.contains(sourcemeta::core::Vocabularies::Known::
JSON_Schema_2020_12_Validation) ||
!schema.is_object() || !schema.defines("type") ||
schema.at("type").to_string() != "integer" ||
!schema.defines("minimum") || !schema.at("minimum").is_integer() ||
!schema.defines("maximum") || !schema.at("maximum").is_integer() ||
!schema.defines("multipleOf") ||
!schema.at("multipleOf").is_integer()) {
return false;
}
return is_byte(count_multiples(schema.at("minimum").to_integer(),
schema.at("maximum").to_integer(),
schema.at("multipleOf").to_integer()));
}
auto transform(sourcemeta::core::JSON &schema,
const sourcemeta::blaze::SchemaTransformRule::Result &) const
-> void override {
auto minimum = schema.at("minimum");
auto maximum = schema.at("maximum");
auto multiplier = schema.at("multipleOf");
auto options = sourcemeta::core::JSON::make_object();
options.assign("minimum", std::move(minimum));
options.assign("maximum", std::move(maximum));
options.assign("multiplier", std::move(multiplier));
make_encoding(schema, "BOUNDED_MULTIPLE_8BITS_ENUM_FIXED", options);
}
};