Skip to content

Commit a9f3934

Browse files
authored
Adopt Tag URIs to define encoding schemas (#810)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 831c916 commit a9f3934

File tree

42 files changed

+81
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+81
-87
lines changed

src/compiler/compiler.cc

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,22 @@
33
#include <sourcemeta/jsonbinpack/compiler.h>
44
#include <sourcemeta/jsontoolkit/jsonschema.h>
55

6-
#include <cassert> // assert
7-
#include <cstdint> // std::int64_t
8-
#include <future> // std::future
9-
#include <limits> // std::numeric_limits
10-
#include <optional> // std::optional
11-
#include <stdexcept> // std::domain_error
12-
#include <string> // std::string
6+
#include <cassert> // assert
7+
#include <future> // std::future
8+
#include <limits> // std::numeric_limits
139

1410
#include "states.h"
1511

1612
namespace {
17-
// TODO: Turn this into a URN
18-
constexpr auto ENCODING_V1{
19-
"https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json"};
13+
constexpr auto ENCODING_V1{"tag:sourcemeta.com,2024:jsonbinpack/encoding/v1"};
2014
auto make_resolver(const sourcemeta::jsontoolkit::SchemaResolver &fallback)
2115
-> auto {
2216
return [&fallback](std::string_view identifier)
2317
-> std::future<std::optional<sourcemeta::jsontoolkit::JSON>> {
2418
std::promise<std::optional<sourcemeta::jsontoolkit::JSON>> promise;
2519
if (identifier == ENCODING_V1) {
2620
promise.set_value(sourcemeta::jsontoolkit::parse(R"JSON({
27-
"$id": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
21+
"$id": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
2822
"$schema": "https://json-schema.org/draft/2020-12/schema",
2923
"$vocabulary": { "https://json-schema.org/draft/2020-12/vocab/core": true }
3024
})JSON"));

test/cli/instance_integer_encoding.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
2+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
33
"name": "TOP_LEVEL_BYTE_CHOICE_INDEX",
44
"options": {
55
"choices": [ 1, 2, 3 ]

test/compiler/2020_12_compiler_any_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ TEST(JSONBinPack_Compiler_Any_2020_12, only_metaschema) {
1515

1616
const sourcemeta::jsontoolkit::JSON expected =
1717
sourcemeta::jsontoolkit::parse(R"JSON({
18-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
18+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
1919
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
2020
"options": {}
2121
})JSON");
@@ -33,7 +33,7 @@ TEST(JSONBinPack_Compiler_Any_2020_12, empty) {
3333

3434
const sourcemeta::jsontoolkit::JSON expected =
3535
sourcemeta::jsontoolkit::parse(R"JSON({
36-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
36+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
3737
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
3838
"options": {}
3939
})JSON");

test/compiler/2020_12_compiler_enum_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ TEST(JSONBinPack_Compiler_Enum_2020_12, enum_singleton) {
1616

1717
const sourcemeta::jsontoolkit::JSON expected =
1818
sourcemeta::jsontoolkit::parse(R"JSON({
19-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
19+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
2020
"name": "CONST_NONE",
2121
"options": {
2222
"value": 2
@@ -39,7 +39,7 @@ TEST(JSONBinPack_Compiler_Enum_2020_12, const_scalar) {
3939

4040
const sourcemeta::jsontoolkit::JSON expected =
4141
sourcemeta::jsontoolkit::parse(R"JSON({
42-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
42+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
4343
"name": "CONST_NONE",
4444
"options": {
4545
"value": 2
@@ -62,7 +62,7 @@ TEST(JSONBinPack_Compiler_Enum_2020_12, enum_small_top_level) {
6262

6363
const sourcemeta::jsontoolkit::JSON expected =
6464
sourcemeta::jsontoolkit::parse(R"JSON({
65-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
65+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
6666
"name": "TOP_LEVEL_BYTE_CHOICE_INDEX",
6767
"options": {
6868
"choices": [ 1, 2, 3 ]

test/compiler/2020_12_compiler_integer_test.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, maximum_minimum_8_bit) {
1818

1919
const sourcemeta::jsontoolkit::JSON expected =
2020
sourcemeta::jsontoolkit::parse(R"JSON({
21-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
21+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
2222
"name": "BOUNDED_MULTIPLE_8BITS_ENUM_FIXED",
2323
"options": {
2424
"minimum": -100,
@@ -46,7 +46,7 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, maximum_minimum_multiplier_8_bit) {
4646

4747
const sourcemeta::jsontoolkit::JSON expected =
4848
sourcemeta::jsontoolkit::parse(R"JSON({
49-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
49+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
5050
"name": "BOUNDED_MULTIPLE_8BITS_ENUM_FIXED",
5151
"options": {
5252
"minimum": -100,
@@ -73,7 +73,7 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, maximum_minimum_greater_than_8_bit) {
7373

7474
const sourcemeta::jsontoolkit::JSON expected =
7575
sourcemeta::jsontoolkit::parse(R"JSON({
76-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
76+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
7777
"name": "FLOOR_MULTIPLE_ENUM_VARINT",
7878
"options": {
7979
"minimum": -100,
@@ -101,7 +101,7 @@ TEST(JSONBinPack_Compiler_Integer_2020_12,
101101

102102
const sourcemeta::jsontoolkit::JSON expected =
103103
sourcemeta::jsontoolkit::parse(R"JSON({
104-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
104+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
105105
"name": "FLOOR_MULTIPLE_ENUM_VARINT",
106106
"options": {
107107
"minimum": -100,
@@ -126,7 +126,7 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, minimum) {
126126

127127
const sourcemeta::jsontoolkit::JSON expected =
128128
sourcemeta::jsontoolkit::parse(R"JSON({
129-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
129+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
130130
"name": "FLOOR_MULTIPLE_ENUM_VARINT",
131131
"options": {
132132
"minimum": 0,
@@ -152,7 +152,7 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, minimum_multiplier) {
152152

153153
const sourcemeta::jsontoolkit::JSON expected =
154154
sourcemeta::jsontoolkit::parse(R"JSON({
155-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
155+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
156156
"name": "FLOOR_MULTIPLE_ENUM_VARINT",
157157
"options": {
158158
"minimum": 0,
@@ -177,7 +177,7 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, maximum) {
177177

178178
const sourcemeta::jsontoolkit::JSON expected =
179179
sourcemeta::jsontoolkit::parse(R"JSON({
180-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
180+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
181181
"name": "ROOF_MULTIPLE_MIRROR_ENUM_VARINT",
182182
"options": {
183183
"maximum": 100,
@@ -203,7 +203,7 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, maximum_multiplier) {
203203

204204
const sourcemeta::jsontoolkit::JSON expected =
205205
sourcemeta::jsontoolkit::parse(R"JSON({
206-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
206+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
207207
"name": "ROOF_MULTIPLE_MIRROR_ENUM_VARINT",
208208
"options": {
209209
"maximum": 100,
@@ -227,7 +227,7 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, unbounded) {
227227

228228
const sourcemeta::jsontoolkit::JSON expected =
229229
sourcemeta::jsontoolkit::parse(R"JSON({
230-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
230+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
231231
"name": "ARBITRARY_MULTIPLE_ZIGZAG_VARINT",
232232
"options": {
233233
"multiplier": 1
@@ -251,7 +251,7 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, unbounded_multiplier) {
251251

252252
const sourcemeta::jsontoolkit::JSON expected =
253253
sourcemeta::jsontoolkit::parse(R"JSON({
254-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
254+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
255255
"name": "ARBITRARY_MULTIPLE_ZIGZAG_VARINT",
256256
"options": {
257257
"multiplier": 5

test/compiler/2020_12_compiler_number_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ TEST(JSONBinPack_Compiler_Number_2020_12, arbitrary) {
1616

1717
const sourcemeta::jsontoolkit::JSON expected =
1818
sourcemeta::jsontoolkit::parse(R"JSON({
19-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
19+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
2020
"name": "DOUBLE_VARINT_TUPLE",
2121
"options": {}
2222
})JSON");

test/compiler/compiler_test.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ TEST(JSONBinPack_Compiler, dialect_2020_12) {
1515
sourcemeta::jsontoolkit::official_resolver);
1616

1717
const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
18-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
18+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
1919
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
2020
"options": {}
2121
})JSON");
@@ -33,7 +33,7 @@ TEST(JSONBinPack_Compiler, dialect_2019_09) {
3333
sourcemeta::jsontoolkit::official_resolver);
3434

3535
const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
36-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
36+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
3737
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
3838
"options": {}
3939
})JSON");
@@ -51,7 +51,7 @@ TEST(JSONBinPack_Compiler, dialect_draft7) {
5151
sourcemeta::jsontoolkit::official_resolver);
5252

5353
const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
54-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
54+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
5555
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
5656
"options": {}
5757
})JSON");
@@ -69,7 +69,7 @@ TEST(JSONBinPack_Compiler, dialect_draft6) {
6969
sourcemeta::jsontoolkit::official_resolver);
7070

7171
const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
72-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
72+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
7373
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
7474
"options": {}
7575
})JSON");
@@ -87,7 +87,7 @@ TEST(JSONBinPack_Compiler, dialect_draft4) {
8787
sourcemeta::jsontoolkit::official_resolver);
8888

8989
const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
90-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
90+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
9191
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
9292
"options": {}
9393
})JSON");
@@ -105,7 +105,7 @@ TEST(JSONBinPack_Compiler, dialect_draft3) {
105105
sourcemeta::jsontoolkit::official_resolver);
106106

107107
const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
108-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
108+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
109109
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
110110
"options": {}
111111
})JSON");
@@ -123,7 +123,7 @@ TEST(JSONBinPack_Compiler, dialect_draft2) {
123123
sourcemeta::jsontoolkit::official_resolver);
124124

125125
const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
126-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
126+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
127127
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
128128
"options": {}
129129
})JSON");
@@ -141,7 +141,7 @@ TEST(JSONBinPack_Compiler, dialect_draft1) {
141141
sourcemeta::jsontoolkit::official_resolver);
142142

143143
const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
144-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
144+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
145145
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
146146
"options": {}
147147
})JSON");
@@ -159,7 +159,7 @@ TEST(JSONBinPack_Compiler, dialect_draft0) {
159159
sourcemeta::jsontoolkit::official_resolver);
160160

161161
const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
162-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
162+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
163163
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
164164
"options": {}
165165
})JSON");
@@ -178,7 +178,7 @@ TEST(JSONBinPack_Compiler, unknown_dialect_default) {
178178
"https://json-schema.org/draft/2020-12/schema");
179179

180180
const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
181-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
181+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
182182
"name": "ARBITRARY_MULTIPLE_ZIGZAG_VARINT",
183183
"options": {
184184
"multiplier": 1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
2+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
33
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
44
"options": {}
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
2+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
33
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
44
"options": {}
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://jsonbinpack.sourcemeta.com/schemas/encoding/v1.json",
2+
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
33
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
44
"options": {}
55
}

0 commit comments

Comments
 (0)