Skip to content

Commit c85a32b

Browse files
authored
Split loader header per type (#839)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 2eaffb6 commit c85a32b

File tree

8 files changed

+342
-284
lines changed

8 files changed

+342
-284
lines changed

src/runtime/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ noa_library(NAMESPACE sourcemeta PROJECT jsonbinpack NAME runtime
77
encoder_context.h
88
plan.h plan_wrap.h
99
SOURCES
10-
loader.cc loader_v1.h varint.h
1110
input_stream.cc
1211
output_stream.cc
12+
varint.h
13+
14+
loader.cc
15+
loader_v1_any.h
16+
loader_v1_array.h
17+
loader_v1_integer.h
18+
loader_v1_number.h
19+
loader_v1_string.h
20+
1321
decoder_any.cc
1422
decoder_array.cc
1523
decoder_common.cc

src/runtime/loader.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include <sourcemeta/jsonbinpack/runtime.h>
22

3-
#include "loader_v1.h"
3+
#include "loader_v1_any.h"
4+
#include "loader_v1_array.h"
5+
#include "loader_v1_integer.h"
6+
#include "loader_v1_number.h"
7+
#include "loader_v1_string.h"
48

59
#include <cassert> // assert
610
#include <sstream> // std::ostringstream
@@ -42,6 +46,7 @@ auto load(const sourcemeta::jsontoolkit::JSON &input) -> Plan {
4246
PARSE_ENCODING(v1, BOUNDED_8BITS_TYPED_ARRAY)
4347
PARSE_ENCODING(v1, FLOOR_TYPED_ARRAY)
4448
PARSE_ENCODING(v1, ROOF_TYPED_ARRAY)
49+
// TODO: Handle object encodings
4550
// Any
4651
PARSE_ENCODING(v1, ANY_PACKED_TYPE_TAG_BYTE_PREFIX)
4752

src/runtime/loader_v1.h

Lines changed: 0 additions & 282 deletions
This file was deleted.

src/runtime/loader_v1_any.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef SOURCEMETA_JSONBINPACK_LOADER_V1_ANY_H_
2+
#define SOURCEMETA_JSONBINPACK_LOADER_V1_ANY_H_
3+
4+
#include <sourcemeta/jsonbinpack/runtime.h>
5+
6+
#include <sourcemeta/jsontoolkit/json.h>
7+
8+
#include <cassert> // assert
9+
#include <utility> // std::move
10+
#include <vector> // std::vector
11+
12+
namespace sourcemeta::jsonbinpack::v1 {
13+
14+
auto BYTE_CHOICE_INDEX(const sourcemeta::jsontoolkit::JSON &options) -> Plan {
15+
assert(options.defines("choices"));
16+
const auto &choices{options.at("choices")};
17+
assert(choices.is_array());
18+
const auto &array{choices.as_array()};
19+
std::vector<sourcemeta::jsontoolkit::JSON> elements{array.cbegin(),
20+
array.cend()};
21+
return sourcemeta::jsonbinpack::BYTE_CHOICE_INDEX({std::move(elements)});
22+
}
23+
24+
auto LARGE_CHOICE_INDEX(const sourcemeta::jsontoolkit::JSON &options) -> Plan {
25+
assert(options.defines("choices"));
26+
const auto &choices{options.at("choices")};
27+
assert(choices.is_array());
28+
const auto &array{choices.as_array()};
29+
std::vector<sourcemeta::jsontoolkit::JSON> elements{array.cbegin(),
30+
array.cend()};
31+
return sourcemeta::jsonbinpack::LARGE_CHOICE_INDEX({std::move(elements)});
32+
}
33+
34+
auto TOP_LEVEL_BYTE_CHOICE_INDEX(const sourcemeta::jsontoolkit::JSON &options)
35+
-> Plan {
36+
assert(options.defines("choices"));
37+
const auto &choices{options.at("choices")};
38+
assert(choices.is_array());
39+
const auto &array{choices.as_array()};
40+
std::vector<sourcemeta::jsontoolkit::JSON> elements{array.cbegin(),
41+
array.cend()};
42+
return sourcemeta::jsonbinpack::TOP_LEVEL_BYTE_CHOICE_INDEX(
43+
{std::move(elements)});
44+
}
45+
46+
auto CONST_NONE(const sourcemeta::jsontoolkit::JSON &options) -> Plan {
47+
assert(options.defines("value"));
48+
return sourcemeta::jsonbinpack::CONST_NONE({options.at("value")});
49+
}
50+
51+
auto ANY_PACKED_TYPE_TAG_BYTE_PREFIX(const sourcemeta::jsontoolkit::JSON &)
52+
-> Plan {
53+
return sourcemeta::jsonbinpack::ANY_PACKED_TYPE_TAG_BYTE_PREFIX{};
54+
}
55+
56+
} // namespace sourcemeta::jsonbinpack::v1
57+
58+
#endif

0 commit comments

Comments
 (0)