Skip to content

Commit

Permalink
Prefix encoding schema properties with binpack (#812)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Sep 27, 2024
1 parent a3a9103 commit 8162f87
Show file tree
Hide file tree
Showing 43 changed files with 182 additions and 182 deletions.
4 changes: 2 additions & 2 deletions src/compiler/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ auto make_encoding(sourcemeta::alterschema::Transformer &document,
const sourcemeta::jsontoolkit::JSON &options) -> void {
document.replace(sourcemeta::jsontoolkit::JSON::make_object());
document.assign("$schema", sourcemeta::jsontoolkit::JSON{ENCODING_V1});
document.assign("name", sourcemeta::jsontoolkit::JSON{encoding});
document.assign("options", options);
document.assign("binpackEncoding", sourcemeta::jsontoolkit::JSON{encoding});
document.assign("binpackOptions", options);
}

// TODO: Re-use from numeric library
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/runtime_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
namespace sourcemeta::jsonbinpack {

auto parse(const sourcemeta::jsontoolkit::JSON &input) -> Plan {
assert(input.defines("name"));
assert(input.defines("options"));
const auto encoding{input.at("name").to_string()};
const auto &options{input.at("options")};
assert(input.defines("binpackEncoding"));
assert(input.defines("binpackOptions"));
const auto encoding{input.at("binpackEncoding").to_string()};
const auto &options{input.at("binpackOptions")};

#define PARSE_ENCODING(version, name) \
if (encoding == #name) \
Expand Down
4 changes: 2 additions & 2 deletions test/cli/instance_integer_encoding.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "TOP_LEVEL_BYTE_CHOICE_INDEX",
"options": {
"binpackEncoding": "TOP_LEVEL_BYTE_CHOICE_INDEX",
"binpackOptions": {
"choices": [ 1, 2, 3 ]
}
}
8 changes: 4 additions & 4 deletions test/compiler/2020_12_compiler_any_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ TEST(JSONBinPack_Compiler_Any_2020_12, only_metaschema) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand All @@ -34,8 +34,8 @@ TEST(JSONBinPack_Compiler_Any_2020_12, empty) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand Down
12 changes: 6 additions & 6 deletions test/compiler/2020_12_compiler_enum_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ TEST(JSONBinPack_Compiler_Enum_2020_12, enum_singleton) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "CONST_NONE",
"options": {
"binpackEncoding": "CONST_NONE",
"binpackOptions": {
"value": 2
}
})JSON");
Expand All @@ -40,8 +40,8 @@ TEST(JSONBinPack_Compiler_Enum_2020_12, const_scalar) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "CONST_NONE",
"options": {
"binpackEncoding": "CONST_NONE",
"binpackOptions": {
"value": 2
}
})JSON");
Expand All @@ -63,8 +63,8 @@ TEST(JSONBinPack_Compiler_Enum_2020_12, enum_small_top_level) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "TOP_LEVEL_BYTE_CHOICE_INDEX",
"options": {
"binpackEncoding": "TOP_LEVEL_BYTE_CHOICE_INDEX",
"binpackOptions": {
"choices": [ 1, 2, 3 ]
}
})JSON");
Expand Down
40 changes: 20 additions & 20 deletions test/compiler/2020_12_compiler_integer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, maximum_minimum_8_bit) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "BOUNDED_MULTIPLE_8BITS_ENUM_FIXED",
"options": {
"binpackEncoding": "BOUNDED_MULTIPLE_8BITS_ENUM_FIXED",
"binpackOptions": {
"minimum": -100,
"maximum": 100,
"multiplier": 1
Expand All @@ -47,8 +47,8 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, maximum_minimum_multiplier_8_bit) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "BOUNDED_MULTIPLE_8BITS_ENUM_FIXED",
"options": {
"binpackEncoding": "BOUNDED_MULTIPLE_8BITS_ENUM_FIXED",
"binpackOptions": {
"minimum": -100,
"maximum": 100,
"multiplier": 5
Expand All @@ -74,8 +74,8 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, maximum_minimum_greater_than_8_bit) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "FLOOR_MULTIPLE_ENUM_VARINT",
"options": {
"binpackEncoding": "FLOOR_MULTIPLE_ENUM_VARINT",
"binpackOptions": {
"minimum": -100,
"multiplier": 1
}
Expand All @@ -102,8 +102,8 @@ TEST(JSONBinPack_Compiler_Integer_2020_12,
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "FLOOR_MULTIPLE_ENUM_VARINT",
"options": {
"binpackEncoding": "FLOOR_MULTIPLE_ENUM_VARINT",
"binpackOptions": {
"minimum": -100,
"multiplier": 5
}
Expand All @@ -127,8 +127,8 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, minimum) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "FLOOR_MULTIPLE_ENUM_VARINT",
"options": {
"binpackEncoding": "FLOOR_MULTIPLE_ENUM_VARINT",
"binpackOptions": {
"minimum": 0,
"multiplier": 1
}
Expand All @@ -153,8 +153,8 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, minimum_multiplier) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "FLOOR_MULTIPLE_ENUM_VARINT",
"options": {
"binpackEncoding": "FLOOR_MULTIPLE_ENUM_VARINT",
"binpackOptions": {
"minimum": 0,
"multiplier": 5
}
Expand All @@ -178,8 +178,8 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, maximum) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ROOF_MULTIPLE_MIRROR_ENUM_VARINT",
"options": {
"binpackEncoding": "ROOF_MULTIPLE_MIRROR_ENUM_VARINT",
"binpackOptions": {
"maximum": 100,
"multiplier": 1
}
Expand All @@ -204,8 +204,8 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, maximum_multiplier) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ROOF_MULTIPLE_MIRROR_ENUM_VARINT",
"options": {
"binpackEncoding": "ROOF_MULTIPLE_MIRROR_ENUM_VARINT",
"binpackOptions": {
"maximum": 100,
"multiplier": 5
}
Expand All @@ -228,8 +228,8 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, unbounded) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ARBITRARY_MULTIPLE_ZIGZAG_VARINT",
"options": {
"binpackEncoding": "ARBITRARY_MULTIPLE_ZIGZAG_VARINT",
"binpackOptions": {
"multiplier": 1
}
})JSON");
Expand All @@ -252,8 +252,8 @@ TEST(JSONBinPack_Compiler_Integer_2020_12, unbounded_multiplier) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ARBITRARY_MULTIPLE_ZIGZAG_VARINT",
"options": {
"binpackEncoding": "ARBITRARY_MULTIPLE_ZIGZAG_VARINT",
"binpackOptions": {
"multiplier": 5
}
})JSON");
Expand Down
4 changes: 2 additions & 2 deletions test/compiler/2020_12_compiler_number_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ TEST(JSONBinPack_Compiler_Number_2020_12, arbitrary) {
const sourcemeta::jsontoolkit::JSON expected =
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "DOUBLE_VARINT_TUPLE",
"options": {}
"binpackEncoding": "DOUBLE_VARINT_TUPLE",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand Down
40 changes: 20 additions & 20 deletions test/compiler/compiler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ TEST(JSONBinPack_Compiler, dialect_2020_12) {

const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand All @@ -34,8 +34,8 @@ TEST(JSONBinPack_Compiler, dialect_2019_09) {

const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand All @@ -52,8 +52,8 @@ TEST(JSONBinPack_Compiler, dialect_draft7) {

const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand All @@ -70,8 +70,8 @@ TEST(JSONBinPack_Compiler, dialect_draft6) {

const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand All @@ -88,8 +88,8 @@ TEST(JSONBinPack_Compiler, dialect_draft4) {

const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand All @@ -106,8 +106,8 @@ TEST(JSONBinPack_Compiler, dialect_draft3) {

const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand All @@ -124,8 +124,8 @@ TEST(JSONBinPack_Compiler, dialect_draft2) {

const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand All @@ -142,8 +142,8 @@ TEST(JSONBinPack_Compiler, dialect_draft1) {

const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand All @@ -160,8 +160,8 @@ TEST(JSONBinPack_Compiler, dialect_draft0) {

const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
})JSON");

EXPECT_EQ(schema, expected);
Expand All @@ -179,8 +179,8 @@ TEST(JSONBinPack_Compiler, unknown_dialect_default) {

const auto expected = sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ARBITRARY_MULTIPLE_ZIGZAG_VARINT",
"options": {
"binpackEncoding": "ARBITRARY_MULTIPLE_ZIGZAG_VARINT",
"binpackOptions": {
"multiplier": 1
}
})JSON");
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/circleciblank/schema-less/plan.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
}
4 changes: 2 additions & 2 deletions test/e2e/circlecimatrix/schema-less/plan.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
}
4 changes: 2 additions & 2 deletions test/e2e/commitlint/schema-less/plan.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
}
4 changes: 2 additions & 2 deletions test/e2e/commitlintbasic/schema-less/plan.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
}
4 changes: 2 additions & 2 deletions test/e2e/epr/schema-less/plan.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
}
4 changes: 2 additions & 2 deletions test/e2e/eslintrc/schema-less/plan.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
}
4 changes: 2 additions & 2 deletions test/e2e/esmrc/schema-less/plan.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
}
4 changes: 2 additions & 2 deletions test/e2e/geojson/schema-less/plan.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
}
4 changes: 2 additions & 2 deletions test/e2e/githubfundingblank/schema-less/plan.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "tag:sourcemeta.com,2024:jsonbinpack/encoding/v1",
"name": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"options": {}
"binpackEncoding": "ANY_PACKED_TYPE_TAG_BYTE_PREFIX",
"binpackOptions": {}
}
Loading

0 comments on commit 8162f87

Please sign in to comment.