|
| 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