3
3
#include < pybind11/numpy.h>
4
4
#include < pybind11/pytypes.h>
5
5
6
+ #include < map>
6
7
#include < string>
7
8
#include < utility>
8
9
#include < vector>
9
-
10
10
#include < wuffs-unsupported-snapshot.c>
11
11
12
+ #include " wuffs-aux-utils.h"
13
+
12
14
// This API wraps the wuffs_aux API for JSON decoding. The wrapper is needed
13
15
// since the wuffs_aux API uses the callback-based approach which doesn't play
14
16
// well with Python-C++ interop.
@@ -45,7 +47,7 @@ enum class JsonDecoderQuirks : uint32_t {
45
47
// This struct hosts wuffs_aux::DecodeJson arguments in more user- and
46
48
// Python- friendly fashion
47
49
struct JsonDecoderConfig {
48
- std::vector <JsonDecoderQuirks> quirks;
50
+ std::map <JsonDecoderQuirks, uint64_t > quirks;
49
51
std::string json_pointer;
50
52
};
51
53
@@ -107,14 +109,20 @@ const std::string JsonDecoderError::BadDepth =
107
109
const std::string JsonDecoderError::FailedToOpenFile =
108
110
" wuffs_aux_wrap::JsonDecoder::Decode: failed to open file" ;
109
111
// + 1 is for stripping leading '#'
110
- const std::string JsonDecoderError::BadC0ControlCode = wuffs_json__error__bad_c0_control_code + 1 ;
112
+ const std::string JsonDecoderError::BadC0ControlCode =
113
+ wuffs_json__error__bad_c0_control_code + 1 ;
111
114
const std::string JsonDecoderError::BadUtf8 = wuffs_json__error__bad_utf_8 + 1 ;
112
- const std::string JsonDecoderError::BadBackslashEscape = wuffs_json__error__bad_backslash_escape + 1 ;
115
+ const std::string JsonDecoderError::BadBackslashEscape =
116
+ wuffs_json__error__bad_backslash_escape + 1 ;
113
117
const std::string JsonDecoderError::BadInput = wuffs_json__error__bad_input + 1 ;
114
- const std::string JsonDecoderError::BadNewLineInAString = wuffs_json__error__bad_new_line_in_a_string + 1 ;
115
- const std::string JsonDecoderError::BadQuirkCombination = wuffs_json__error__bad_quirk_combination + 1 ;
116
- const std::string JsonDecoderError::UnsupportedNumberLength = wuffs_json__error__unsupported_number_length + 1 ;
117
- const std::string JsonDecoderError::UnsupportedRecursionDepth = wuffs_json__error__unsupported_recursion_depth + 1 ;
118
+ const std::string JsonDecoderError::BadNewLineInAString =
119
+ wuffs_json__error__bad_new_line_in_a_string + 1 ;
120
+ const std::string JsonDecoderError::BadQuirkCombination =
121
+ wuffs_json__error__bad_quirk_combination + 1 ;
122
+ const std::string JsonDecoderError::UnsupportedNumberLength =
123
+ wuffs_json__error__unsupported_number_length + 1 ;
124
+ const std::string JsonDecoderError::UnsupportedRecursionDepth =
125
+ wuffs_json__error__unsupported_recursion_depth + 1 ;
118
126
119
127
class JsonDecoder : public wuffs_aux ::DecodeJsonCallbacks {
120
128
public:
@@ -132,10 +140,9 @@ class JsonDecoder : public wuffs_aux::DecodeJsonCallbacks {
132
140
};
133
141
134
142
explicit JsonDecoder (const JsonDecoderConfig& config)
135
- : quirks_vector_({config.quirks .begin (), config.quirks .end ()}),
136
- quirks_(wuffs_aux::DecodeJsonArgQuirks(
137
- reinterpret_cast <uint32_t *>(quirks_vector_.data()),
138
- quirks_vector_.size())),
143
+ : quirks_vector_(utils::ConvertQuirks(config.quirks)),
144
+ quirks_(wuffs_aux::DecodeJsonArgQuirks(quirks_vector_.data(),
145
+ quirks_vector_.size())),
139
146
json_pointer_(config.json_pointer) {}
140
147
141
148
/* DecodeJsonCallbacks methods implementation */
@@ -247,7 +254,7 @@ class JsonDecoder : public wuffs_aux::DecodeJsonCallbacks {
247
254
}
248
255
249
256
private:
250
- std::vector<JsonDecoderQuirks > quirks_vector_;
257
+ std::vector<wuffs_aux::QuirkKeyValuePair > quirks_vector_;
251
258
wuffs_aux::DecodeJsonArgQuirks quirks_;
252
259
wuffs_aux::DecodeJsonArgJsonPointer json_pointer_;
253
260
std::vector<Entry> stack_;
0 commit comments