jsoncons 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/ext/jsoncons/extconf.rb +43 -0
  3. data/ext/jsoncons/jsoncons.cpp +161 -0
  4. data/ext/jsoncons/jsoncons.h +10 -0
  5. data/jsoncons.gemspec +44 -0
  6. data/lib/jsoncons/jsoncons/examples/input/address-book.json +13 -0
  7. data/lib/jsoncons/jsoncons/examples/input/books.json +28 -0
  8. data/lib/jsoncons/jsoncons/examples/input/countries.json +7 -0
  9. data/lib/jsoncons/jsoncons/examples/input/employees.json +30 -0
  10. data/lib/jsoncons/jsoncons/examples/input/jsonschema/name.json +15 -0
  11. data/lib/jsoncons/jsoncons/examples/input/multiple-json-objects.json +3 -0
  12. data/lib/jsoncons/jsoncons/examples/input/sales.csv +6 -0
  13. data/lib/jsoncons/jsoncons/examples/input/store.json +28 -0
  14. data/lib/jsoncons/jsoncons/examples/input/tasks.csv +6 -0
  15. data/lib/jsoncons/jsoncons/include/jsoncons/allocator_holder.hpp +38 -0
  16. data/lib/jsoncons/jsoncons/include/jsoncons/basic_json.hpp +5905 -0
  17. data/lib/jsoncons/jsoncons/include/jsoncons/bigint.hpp +1611 -0
  18. data/lib/jsoncons/jsoncons/include/jsoncons/byte_string.hpp +820 -0
  19. data/lib/jsoncons/jsoncons/include/jsoncons/config/binary_config.hpp +226 -0
  20. data/lib/jsoncons/jsoncons/include/jsoncons/config/compiler_support.hpp +375 -0
  21. data/lib/jsoncons/jsoncons/include/jsoncons/config/jsoncons_config.hpp +309 -0
  22. data/lib/jsoncons/jsoncons/include/jsoncons/config/version.hpp +40 -0
  23. data/lib/jsoncons/jsoncons/include/jsoncons/conv_error.hpp +218 -0
  24. data/lib/jsoncons/jsoncons/include/jsoncons/decode_json.hpp +209 -0
  25. data/lib/jsoncons/jsoncons/include/jsoncons/decode_traits.hpp +651 -0
  26. data/lib/jsoncons/jsoncons/include/jsoncons/detail/endian.hpp +44 -0
  27. data/lib/jsoncons/jsoncons/include/jsoncons/detail/grisu3.hpp +312 -0
  28. data/lib/jsoncons/jsoncons/include/jsoncons/detail/optional.hpp +483 -0
  29. data/lib/jsoncons/jsoncons/include/jsoncons/detail/parse_number.hpp +1133 -0
  30. data/lib/jsoncons/jsoncons/include/jsoncons/detail/span.hpp +188 -0
  31. data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_view.hpp +537 -0
  32. data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_wrapper.hpp +370 -0
  33. data/lib/jsoncons/jsoncons/include/jsoncons/detail/write_number.hpp +567 -0
  34. data/lib/jsoncons/jsoncons/include/jsoncons/encode_json.hpp +315 -0
  35. data/lib/jsoncons/jsoncons/include/jsoncons/encode_traits.hpp +378 -0
  36. data/lib/jsoncons/jsoncons/include/jsoncons/json.hpp +18 -0
  37. data/lib/jsoncons/jsoncons/include/jsoncons/json_array.hpp +324 -0
  38. data/lib/jsoncons/jsoncons/include/jsoncons/json_content_handler.hpp +12 -0
  39. data/lib/jsoncons/jsoncons/include/jsoncons/json_cursor.hpp +448 -0
  40. data/lib/jsoncons/jsoncons/include/jsoncons/json_decoder.hpp +420 -0
  41. data/lib/jsoncons/jsoncons/include/jsoncons/json_encoder.hpp +1587 -0
  42. data/lib/jsoncons/jsoncons/include/jsoncons/json_error.hpp +156 -0
  43. data/lib/jsoncons/jsoncons/include/jsoncons/json_exception.hpp +241 -0
  44. data/lib/jsoncons/jsoncons/include/jsoncons/json_filter.hpp +653 -0
  45. data/lib/jsoncons/jsoncons/include/jsoncons/json_fwd.hpp +23 -0
  46. data/lib/jsoncons/jsoncons/include/jsoncons/json_object.hpp +1772 -0
  47. data/lib/jsoncons/jsoncons/include/jsoncons/json_options.hpp +862 -0
  48. data/lib/jsoncons/jsoncons/include/jsoncons/json_parser.hpp +2900 -0
  49. data/lib/jsoncons/jsoncons/include/jsoncons/json_reader.hpp +731 -0
  50. data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros.hpp +1072 -0
  51. data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros_deprecated.hpp +144 -0
  52. data/lib/jsoncons/jsoncons/include/jsoncons/json_type.hpp +206 -0
  53. data/lib/jsoncons/jsoncons/include/jsoncons/json_type_traits.hpp +1830 -0
  54. data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor.hpp +1560 -0
  55. data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor2.hpp +2079 -0
  56. data/lib/jsoncons/jsoncons/include/jsoncons/pretty_print.hpp +89 -0
  57. data/lib/jsoncons/jsoncons/include/jsoncons/ser_context.hpp +62 -0
  58. data/lib/jsoncons/jsoncons/include/jsoncons/sink.hpp +289 -0
  59. data/lib/jsoncons/jsoncons/include/jsoncons/source.hpp +777 -0
  60. data/lib/jsoncons/jsoncons/include/jsoncons/source_adaptor.hpp +148 -0
  61. data/lib/jsoncons/jsoncons/include/jsoncons/staj2_cursor.hpp +1189 -0
  62. data/lib/jsoncons/jsoncons/include/jsoncons/staj_cursor.hpp +1254 -0
  63. data/lib/jsoncons/jsoncons/include/jsoncons/staj_iterator.hpp +449 -0
  64. data/lib/jsoncons/jsoncons/include/jsoncons/tag_type.hpp +245 -0
  65. data/lib/jsoncons/jsoncons/include/jsoncons/text_source_adaptor.hpp +144 -0
  66. data/lib/jsoncons/jsoncons/include/jsoncons/traits_extension.hpp +884 -0
  67. data/lib/jsoncons/jsoncons/include/jsoncons/typed_array_view.hpp +250 -0
  68. data/lib/jsoncons/jsoncons/include/jsoncons/unicode_traits.hpp +1330 -0
  69. data/lib/jsoncons/jsoncons/include/jsoncons/uri.hpp +635 -0
  70. data/lib/jsoncons/jsoncons/include/jsoncons/value_converter.hpp +340 -0
  71. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson.hpp +23 -0
  72. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_cursor.hpp +320 -0
  73. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_decimal128.hpp +865 -0
  74. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_encoder.hpp +585 -0
  75. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_error.hpp +103 -0
  76. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_oid.hpp +245 -0
  77. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_options.hpp +75 -0
  78. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_parser.hpp +645 -0
  79. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_reader.hpp +92 -0
  80. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_type.hpp +44 -0
  81. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/decode_bson.hpp +201 -0
  82. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/encode_bson.hpp +144 -0
  83. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor.hpp +26 -0
  84. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor.hpp +351 -0
  85. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor2.hpp +265 -0
  86. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_detail.hpp +93 -0
  87. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_encoder.hpp +1766 -0
  88. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_error.hpp +105 -0
  89. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_options.hpp +113 -0
  90. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_parser.hpp +1942 -0
  91. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_reader.hpp +116 -0
  92. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/decode_cbor.hpp +203 -0
  93. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/encode_cbor.hpp +151 -0
  94. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv.hpp +17 -0
  95. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_cursor.hpp +358 -0
  96. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_encoder.hpp +954 -0
  97. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_error.hpp +85 -0
  98. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_options.hpp +973 -0
  99. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_parser.hpp +2099 -0
  100. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_reader.hpp +348 -0
  101. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_serializer.hpp +12 -0
  102. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/decode_csv.hpp +208 -0
  103. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/encode_csv.hpp +122 -0
  104. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath.hpp +5215 -0
  105. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath_error.hpp +215 -0
  106. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch.hpp +579 -0
  107. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch_error.hpp +121 -0
  108. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/expression.hpp +3329 -0
  109. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/flatten.hpp +432 -0
  110. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_location.hpp +445 -0
  111. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_query.hpp +115 -0
  112. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath.hpp +13 -0
  113. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_error.hpp +240 -0
  114. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +2612 -0
  115. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +1322 -0
  116. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer.hpp +1577 -0
  117. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer_error.hpp +119 -0
  118. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/format_validator.hpp +968 -0
  119. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/json_validator.hpp +120 -0
  120. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema.hpp +13 -0
  121. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_error.hpp +105 -0
  122. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_version.hpp +18 -0
  123. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator.hpp +1745 -0
  124. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator_factory.hpp +556 -0
  125. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_draft7.hpp +198 -0
  126. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_location.hpp +200 -0
  127. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_version.hpp +35 -0
  128. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/subschema.hpp +144 -0
  129. data/lib/jsoncons/jsoncons/include/jsoncons_ext/mergepatch/mergepatch.hpp +103 -0
  130. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/decode_msgpack.hpp +202 -0
  131. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/encode_msgpack.hpp +142 -0
  132. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack.hpp +24 -0
  133. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor.hpp +343 -0
  134. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor2.hpp +259 -0
  135. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_encoder.hpp +753 -0
  136. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_error.hpp +94 -0
  137. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_options.hpp +74 -0
  138. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_parser.hpp +748 -0
  139. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_reader.hpp +116 -0
  140. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_type.hpp +63 -0
  141. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/decode_ubjson.hpp +201 -0
  142. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/encode_ubjson.hpp +142 -0
  143. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson.hpp +23 -0
  144. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_cursor.hpp +307 -0
  145. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_encoder.hpp +502 -0
  146. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_error.hpp +100 -0
  147. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_options.hpp +87 -0
  148. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_parser.hpp +880 -0
  149. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_reader.hpp +92 -0
  150. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_type.hpp +43 -0
  151. data/lib/jsoncons/version.rb +5 -0
  152. data/lib/jsoncons.rb +33 -0
  153. data/test/jsoncons_test.rb +108 -0
  154. data/test/test_helper.rb +7 -0
  155. metadata +268 -0
@@ -0,0 +1,2079 @@
1
+ // Copyright 2018 Daniel Parker
2
+ // Distributed under the Boost license, Version 1.0.
3
+ // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
+
5
+ // See https://github.com/danielaparker/jsoncons for latest version
6
+
7
+ #ifndef JSONCONS_JSON_VISITOR2_HPP
8
+ #define JSONCONS_JSON_VISITOR2_HPP
9
+
10
+ #include <jsoncons/json_visitor.hpp>
11
+ #include <jsoncons/json_encoder.hpp>
12
+
13
+ namespace jsoncons {
14
+
15
+ template <class CharT, class Allocator = std::allocator<char>>
16
+ class basic_json_visitor2_to_visitor_adaptor;
17
+
18
+ template <class CharT>
19
+ class basic_json_visitor2
20
+ {
21
+ template <class Ch, class Allocator>
22
+ friend class basic_json_visitor2_to_visitor_adaptor;
23
+ public:
24
+ using char_type = CharT;
25
+ using char_traits_type = std::char_traits<char_type>;
26
+
27
+ using string_view_type = jsoncons::basic_string_view<char_type,char_traits_type>;
28
+
29
+ basic_json_visitor2(basic_json_visitor2&&) = default;
30
+
31
+ basic_json_visitor2& operator=(basic_json_visitor2&&) = default;
32
+
33
+ basic_json_visitor2() = default;
34
+
35
+ virtual ~basic_json_visitor2() noexcept = default;
36
+
37
+ void flush()
38
+ {
39
+ visit_flush();
40
+ }
41
+
42
+ bool begin_object(semantic_tag tag=semantic_tag::none,
43
+ const ser_context& context=ser_context())
44
+ {
45
+ std::error_code ec;
46
+ bool more = visit_begin_object(tag, context, ec);
47
+ if (ec)
48
+ {
49
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
50
+ }
51
+ return more;
52
+ }
53
+
54
+ bool begin_object(std::size_t length,
55
+ semantic_tag tag=semantic_tag::none,
56
+ const ser_context& context = ser_context())
57
+ {
58
+ std::error_code ec;
59
+ bool more = visit_begin_object(length, tag, context, ec);
60
+ if (ec)
61
+ {
62
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
63
+ }
64
+ return more;
65
+ }
66
+
67
+ bool end_object(const ser_context& context = ser_context())
68
+ {
69
+ std::error_code ec;
70
+ bool more = visit_end_object(context, ec);
71
+ if (ec)
72
+ {
73
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
74
+ }
75
+ return more;
76
+ }
77
+
78
+ bool begin_array(semantic_tag tag=semantic_tag::none,
79
+ const ser_context& context=ser_context())
80
+ {
81
+ std::error_code ec;
82
+ bool more = visit_begin_array(tag, context, ec);
83
+ if (ec)
84
+ {
85
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
86
+ }
87
+ return more;
88
+ }
89
+
90
+ bool begin_array(std::size_t length,
91
+ semantic_tag tag=semantic_tag::none,
92
+ const ser_context& context=ser_context())
93
+ {
94
+ std::error_code ec;
95
+ bool more = visit_begin_array(length, tag, context, ec);
96
+ if (ec)
97
+ {
98
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
99
+ }
100
+ return more;
101
+ }
102
+
103
+ bool end_array(const ser_context& context=ser_context())
104
+ {
105
+ std::error_code ec;
106
+ bool more = visit_end_array(context, ec);
107
+ if (ec)
108
+ {
109
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
110
+ }
111
+ return more;
112
+ }
113
+
114
+ bool key(const string_view_type& name, const ser_context& context=ser_context())
115
+ {
116
+ std::error_code ec;
117
+ bool more = visit_string(name, semantic_tag::none, context, ec);
118
+ if (ec)
119
+ {
120
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
121
+ }
122
+ return more;
123
+ }
124
+
125
+ bool null_value(semantic_tag tag = semantic_tag::none,
126
+ const ser_context& context=ser_context())
127
+ {
128
+ std::error_code ec;
129
+ bool more = visit_null(tag, context, ec);
130
+ if (ec)
131
+ {
132
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
133
+ }
134
+ return more;
135
+ }
136
+
137
+ bool bool_value(bool value,
138
+ semantic_tag tag = semantic_tag::none,
139
+ const ser_context& context=ser_context())
140
+ {
141
+ std::error_code ec;
142
+ bool more = visit_bool(value, tag, context, ec);
143
+ if (ec)
144
+ {
145
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
146
+ }
147
+ return more;
148
+ }
149
+
150
+ bool string_value(const string_view_type& value,
151
+ semantic_tag tag = semantic_tag::none,
152
+ const ser_context& context=ser_context())
153
+ {
154
+ std::error_code ec;
155
+ bool more = visit_string(value, tag, context, ec);
156
+ if (ec)
157
+ {
158
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
159
+ }
160
+ return more;
161
+ }
162
+
163
+ template <class Source>
164
+ bool byte_string_value(const Source& b,
165
+ semantic_tag tag=semantic_tag::none,
166
+ const ser_context& context=ser_context(),
167
+ typename std::enable_if<traits_extension::is_byte_sequence<Source>::value,int>::type = 0)
168
+ {
169
+ std::error_code ec;
170
+ bool more = visit_byte_string(byte_string_view(reinterpret_cast<const uint8_t*>(b.data()),b.size()), tag, context, ec);
171
+ if (ec)
172
+ {
173
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
174
+ }
175
+ return more;
176
+ }
177
+
178
+ template <class Source>
179
+ bool byte_string_value(const Source& b,
180
+ uint64_t ext_tag,
181
+ const ser_context& context=ser_context(),
182
+ typename std::enable_if<traits_extension::is_byte_sequence<Source>::value,int>::type = 0)
183
+ {
184
+ std::error_code ec;
185
+ bool more = visit_byte_string(byte_string_view(reinterpret_cast<const uint8_t*>(b.data()),b.size()), ext_tag, context, ec);
186
+ if (ec)
187
+ {
188
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
189
+ }
190
+ return more;
191
+ }
192
+
193
+ bool uint64_value(uint64_t value,
194
+ semantic_tag tag = semantic_tag::none,
195
+ const ser_context& context=ser_context())
196
+ {
197
+ std::error_code ec;
198
+ bool more = visit_uint64(value, tag, context, ec);
199
+ if (ec)
200
+ {
201
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
202
+ }
203
+ return more;
204
+ }
205
+
206
+ bool int64_value(int64_t value,
207
+ semantic_tag tag = semantic_tag::none,
208
+ const ser_context& context=ser_context())
209
+ {
210
+ std::error_code ec;
211
+ bool more = visit_int64(value, tag, context, ec);
212
+ if (ec)
213
+ {
214
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
215
+ }
216
+ return more;
217
+ }
218
+
219
+ bool half_value(uint16_t value,
220
+ semantic_tag tag = semantic_tag::none,
221
+ const ser_context& context=ser_context())
222
+ {
223
+ std::error_code ec;
224
+ bool more = visit_half(value, tag, context, ec);
225
+ if (ec)
226
+ {
227
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
228
+ }
229
+ return more;
230
+ }
231
+
232
+ bool double_value(double value,
233
+ semantic_tag tag = semantic_tag::none,
234
+ const ser_context& context=ser_context())
235
+ {
236
+ std::error_code ec;
237
+ bool more = visit_double(value, tag, context, ec);
238
+ if (ec)
239
+ {
240
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
241
+ }
242
+ return more;
243
+ }
244
+
245
+ bool begin_object(semantic_tag tag,
246
+ const ser_context& context,
247
+ std::error_code& ec)
248
+ {
249
+ return visit_begin_object(tag, context, ec);
250
+ }
251
+
252
+ bool begin_object(std::size_t length,
253
+ semantic_tag tag,
254
+ const ser_context& context,
255
+ std::error_code& ec)
256
+ {
257
+ return visit_begin_object(length, tag, context, ec);
258
+ }
259
+
260
+ bool end_object(const ser_context& context, std::error_code& ec)
261
+ {
262
+ return visit_end_object(context, ec);
263
+ }
264
+
265
+ bool begin_array(semantic_tag tag, const ser_context& context, std::error_code& ec)
266
+ {
267
+ return visit_begin_array(tag, context, ec);
268
+ }
269
+
270
+ bool begin_array(std::size_t length, semantic_tag tag, const ser_context& context, std::error_code& ec)
271
+ {
272
+ return visit_begin_array(length, tag, context, ec);
273
+ }
274
+
275
+ bool end_array(const ser_context& context, std::error_code& ec)
276
+ {
277
+ return visit_end_array(context, ec);
278
+ }
279
+
280
+ bool key(const string_view_type& name, const ser_context& context, std::error_code& ec)
281
+ {
282
+ return visit_string(name, semantic_tag::none, context, ec);
283
+ }
284
+
285
+ bool null_value(semantic_tag tag,
286
+ const ser_context& context,
287
+ std::error_code& ec)
288
+ {
289
+ return visit_null(tag, context, ec);
290
+ }
291
+
292
+ bool bool_value(bool value,
293
+ semantic_tag tag,
294
+ const ser_context& context,
295
+ std::error_code& ec)
296
+ {
297
+ return visit_bool(value, tag, context, ec);
298
+ }
299
+
300
+ bool string_value(const string_view_type& value,
301
+ semantic_tag tag,
302
+ const ser_context& context,
303
+ std::error_code& ec)
304
+ {
305
+ return visit_string(value, tag, context, ec);
306
+ }
307
+
308
+ template <class Source>
309
+ bool byte_string_value(const Source& b,
310
+ semantic_tag tag,
311
+ const ser_context& context,
312
+ std::error_code& ec,
313
+ typename std::enable_if<traits_extension::is_byte_sequence<Source>::value,int>::type = 0)
314
+ {
315
+ return visit_byte_string(byte_string_view(reinterpret_cast<const uint8_t*>(b.data()),b.size()), tag, context, ec);
316
+ }
317
+
318
+ template <class Source>
319
+ bool byte_string_value(const Source& b,
320
+ uint64_t ext_tag,
321
+ const ser_context& context,
322
+ std::error_code& ec,
323
+ typename std::enable_if<traits_extension::is_byte_sequence<Source>::value,int>::type = 0)
324
+ {
325
+ return visit_byte_string(byte_string_view(reinterpret_cast<const uint8_t*>(b.data()),b.size()), ext_tag, context, ec);
326
+ }
327
+
328
+ bool uint64_value(uint64_t value,
329
+ semantic_tag tag,
330
+ const ser_context& context,
331
+ std::error_code& ec)
332
+ {
333
+ return visit_uint64(value, tag, context, ec);
334
+ }
335
+
336
+ bool int64_value(int64_t value,
337
+ semantic_tag tag,
338
+ const ser_context& context,
339
+ std::error_code& ec)
340
+ {
341
+ return visit_int64(value, tag, context, ec);
342
+ }
343
+
344
+ bool half_value(uint16_t value,
345
+ semantic_tag tag,
346
+ const ser_context& context,
347
+ std::error_code& ec)
348
+ {
349
+ return visit_half(value, tag, context, ec);
350
+ }
351
+
352
+ bool double_value(double value,
353
+ semantic_tag tag,
354
+ const ser_context& context,
355
+ std::error_code& ec)
356
+ {
357
+ return visit_double(value, tag, context, ec);
358
+ }
359
+
360
+ template <class T>
361
+ bool typed_array(const jsoncons::span<T>& data,
362
+ semantic_tag tag=semantic_tag::none,
363
+ const ser_context& context=ser_context())
364
+ {
365
+ std::error_code ec;
366
+ bool more = visit_typed_array(data, tag, context, ec);
367
+ if (ec)
368
+ {
369
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
370
+ }
371
+ return more;
372
+ }
373
+
374
+ template <class T>
375
+ bool typed_array(const jsoncons::span<T>& data,
376
+ semantic_tag tag,
377
+ const ser_context& context,
378
+ std::error_code& ec)
379
+ {
380
+ return visit_typed_array(data, tag, context, ec);
381
+ }
382
+
383
+ bool typed_array(half_arg_t, const jsoncons::span<const uint16_t>& s,
384
+ semantic_tag tag = semantic_tag::none,
385
+ const ser_context& context = ser_context())
386
+ {
387
+ std::error_code ec;
388
+ bool more = visit_typed_array(half_arg, s, tag, context, ec);
389
+ if (ec)
390
+ {
391
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
392
+ }
393
+ return more;
394
+ }
395
+
396
+ bool typed_array(half_arg_t, const jsoncons::span<const uint16_t>& s,
397
+ semantic_tag tag,
398
+ const ser_context& context,
399
+ std::error_code& ec)
400
+ {
401
+ return visit_typed_array(half_arg, s, tag, context, ec);
402
+ }
403
+
404
+ bool begin_multi_dim(const jsoncons::span<const size_t>& shape,
405
+ semantic_tag tag = semantic_tag::multi_dim_row_major,
406
+ const ser_context& context=ser_context())
407
+ {
408
+ std::error_code ec;
409
+ bool more = visit_begin_multi_dim(shape, tag, context, ec);
410
+ if (ec)
411
+ {
412
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
413
+ }
414
+ return more;
415
+ }
416
+
417
+ bool begin_multi_dim(const jsoncons::span<const size_t>& shape,
418
+ semantic_tag tag,
419
+ const ser_context& context,
420
+ std::error_code& ec)
421
+ {
422
+ return visit_begin_multi_dim(shape, tag, context, ec);
423
+ }
424
+
425
+ bool end_multi_dim(const ser_context& context=ser_context())
426
+ {
427
+ std::error_code ec;
428
+ bool more = visit_end_multi_dim(context, ec);
429
+ if (ec)
430
+ {
431
+ JSONCONS_THROW(ser_error(ec, context.line(), context.column()));
432
+ }
433
+ return more;
434
+ }
435
+
436
+ bool end_multi_dim(const ser_context& context,
437
+ std::error_code& ec)
438
+ {
439
+ return visit_end_multi_dim(context, ec);
440
+ }
441
+
442
+ private:
443
+
444
+ virtual void visit_flush() = 0;
445
+
446
+ virtual bool visit_begin_object(semantic_tag tag,
447
+ const ser_context& context,
448
+ std::error_code& ec) = 0;
449
+
450
+ virtual bool visit_begin_object(std::size_t /*length*/,
451
+ semantic_tag tag,
452
+ const ser_context& context,
453
+ std::error_code& ec)
454
+ {
455
+ return visit_begin_object(tag, context, ec);
456
+ }
457
+
458
+ virtual bool visit_end_object(const ser_context& context,
459
+ std::error_code& ec) = 0;
460
+
461
+ virtual bool visit_begin_array(semantic_tag tag,
462
+ const ser_context& context,
463
+ std::error_code& ec) = 0;
464
+
465
+ virtual bool visit_begin_array(std::size_t /*length*/,
466
+ semantic_tag tag,
467
+ const ser_context& context,
468
+ std::error_code& ec)
469
+ {
470
+ return visit_begin_array(tag, context, ec);
471
+ }
472
+
473
+ virtual bool visit_end_array(const ser_context& context,
474
+ std::error_code& ec) = 0;
475
+
476
+ virtual bool visit_null(semantic_tag tag,
477
+ const ser_context& context,
478
+ std::error_code& ec) = 0;
479
+
480
+ virtual bool visit_bool(bool value,
481
+ semantic_tag tag,
482
+ const ser_context& context,
483
+ std::error_code&) = 0;
484
+
485
+ virtual bool visit_string(const string_view_type& value,
486
+ semantic_tag tag,
487
+ const ser_context& context,
488
+ std::error_code& ec) = 0;
489
+
490
+ virtual bool visit_byte_string(const byte_string_view& value,
491
+ semantic_tag tag,
492
+ const ser_context& context,
493
+ std::error_code& ec) = 0;
494
+
495
+ virtual bool visit_byte_string(const byte_string_view& value,
496
+ uint64_t /*ext_tag*/,
497
+ const ser_context& context,
498
+ std::error_code& ec)
499
+ {
500
+ return visit_byte_string(value, semantic_tag::none, context, ec);
501
+ }
502
+
503
+ virtual bool visit_uint64(uint64_t value,
504
+ semantic_tag tag,
505
+ const ser_context& context,
506
+ std::error_code& ec) = 0;
507
+
508
+ virtual bool visit_int64(int64_t value,
509
+ semantic_tag tag,
510
+ const ser_context& context,
511
+ std::error_code& ec) = 0;
512
+
513
+ virtual bool visit_half(uint16_t value,
514
+ semantic_tag tag,
515
+ const ser_context& context,
516
+ std::error_code& ec)
517
+ {
518
+ return visit_double(binary::decode_half(value),
519
+ tag,
520
+ context,
521
+ ec);
522
+ }
523
+
524
+ virtual bool visit_double(double value,
525
+ semantic_tag tag,
526
+ const ser_context& context,
527
+ std::error_code& ec) = 0;
528
+
529
+ virtual bool visit_typed_array(const jsoncons::span<const uint8_t>& s,
530
+ semantic_tag tag,
531
+ const ser_context& context,
532
+ std::error_code& ec)
533
+ {
534
+ bool more = begin_array(s.size(), tag, context, ec);
535
+ for (auto p = s.begin(); more && p != s.end(); ++p)
536
+ {
537
+ more = uint64_value(*p, semantic_tag::none, context, ec);
538
+ }
539
+ if (more)
540
+ {
541
+ more = end_array(context, ec);
542
+ }
543
+ return more;
544
+ }
545
+
546
+ virtual bool visit_typed_array(const jsoncons::span<const uint16_t>& s,
547
+ semantic_tag tag,
548
+ const ser_context& context,
549
+ std::error_code& ec)
550
+ {
551
+ bool more = begin_array(s.size(), tag, context, ec);
552
+ for (auto p = s.begin(); more && p != s.end(); ++p)
553
+ {
554
+ more = uint64_value(*p, semantic_tag::none, context, ec);
555
+ }
556
+ if (more)
557
+ {
558
+ more = end_array(context, ec);
559
+ }
560
+ return more;
561
+ }
562
+
563
+ virtual bool visit_typed_array(const jsoncons::span<const uint32_t>& s,
564
+ semantic_tag tag,
565
+ const ser_context& context,
566
+ std::error_code& ec)
567
+ {
568
+ bool more = begin_array(s.size(), tag, context, ec);
569
+ for (auto p = s.begin(); more && p != s.end(); ++p)
570
+ {
571
+ more = uint64_value(*p, semantic_tag::none, context, ec);
572
+ }
573
+ if (more)
574
+ {
575
+ more = end_array(context, ec);
576
+ }
577
+ return more;
578
+ }
579
+
580
+ virtual bool visit_typed_array(const jsoncons::span<const uint64_t>& s,
581
+ semantic_tag tag,
582
+ const ser_context& context,
583
+ std::error_code& ec)
584
+ {
585
+ bool more = begin_array(s.size(), tag, context, ec);
586
+ for (auto p = s.begin(); more && p != s.end(); ++p)
587
+ {
588
+ more = uint64_value(*p,semantic_tag::none,context, ec);
589
+ }
590
+ if (more)
591
+ {
592
+ more = end_array(context, ec);
593
+ }
594
+ return more;
595
+ }
596
+
597
+ virtual bool visit_typed_array(const jsoncons::span<const int8_t>& s,
598
+ semantic_tag tag,
599
+ const ser_context& context,
600
+ std::error_code& ec)
601
+ {
602
+ bool more = begin_array(s.size(), tag,context, ec);
603
+ for (auto p = s.begin(); more && p != s.end(); ++p)
604
+ {
605
+ more = int64_value(*p,semantic_tag::none,context, ec);
606
+ }
607
+ if (more)
608
+ {
609
+ more = end_array(context, ec);
610
+ }
611
+ return more;
612
+ }
613
+
614
+ virtual bool visit_typed_array(const jsoncons::span<const int16_t>& s,
615
+ semantic_tag tag,
616
+ const ser_context& context,
617
+ std::error_code& ec)
618
+ {
619
+ bool more = begin_array(s.size(), tag,context, ec);
620
+ for (auto p = s.begin(); more && p != s.end(); ++p)
621
+ {
622
+ more = int64_value(*p,semantic_tag::none,context, ec);
623
+ }
624
+ if (more)
625
+ {
626
+ more = end_array(context, ec);
627
+ }
628
+ return more;
629
+ }
630
+
631
+ virtual bool visit_typed_array(const jsoncons::span<const int32_t>& s,
632
+ semantic_tag tag,
633
+ const ser_context& context,
634
+ std::error_code& ec)
635
+ {
636
+ bool more = begin_array(s.size(), tag,context, ec);
637
+ for (auto p = s.begin(); more && p != s.end(); ++p)
638
+ {
639
+ more = int64_value(*p,semantic_tag::none,context, ec);
640
+ }
641
+ if (more)
642
+ {
643
+ more = end_array(context, ec);
644
+ }
645
+ return more;
646
+ }
647
+
648
+ virtual bool visit_typed_array(const jsoncons::span<const int64_t>& s,
649
+ semantic_tag tag,
650
+ const ser_context& context,
651
+ std::error_code& ec)
652
+ {
653
+ bool more = begin_array(s.size(), tag,context, ec);
654
+ for (auto p = s.begin(); more && p != s.end(); ++p)
655
+ {
656
+ more = int64_value(*p,semantic_tag::none,context, ec);
657
+ }
658
+ if (more)
659
+ {
660
+ more = end_array(context, ec);
661
+ }
662
+ return more;
663
+ }
664
+
665
+ virtual bool visit_typed_array(half_arg_t,
666
+ const jsoncons::span<const uint16_t>& s,
667
+ semantic_tag tag,
668
+ const ser_context& context,
669
+ std::error_code& ec)
670
+ {
671
+ bool more = begin_array(s.size(), tag, context, ec);
672
+ for (auto p = s.begin(); more && p != s.end(); ++p)
673
+ {
674
+ more = half_value(*p, semantic_tag::none, context, ec);
675
+ }
676
+ if (more)
677
+ {
678
+ more = end_array(context, ec);
679
+ }
680
+ return more;
681
+ }
682
+
683
+ virtual bool visit_typed_array(const jsoncons::span<const float>& s,
684
+ semantic_tag tag,
685
+ const ser_context& context,
686
+ std::error_code& ec)
687
+ {
688
+ bool more = begin_array(s.size(), tag,context, ec);
689
+ for (auto p = s.begin(); more && p != s.end(); ++p)
690
+ {
691
+ more = double_value(*p,semantic_tag::none,context, ec);
692
+ }
693
+ if (more)
694
+ {
695
+ more = end_array(context, ec);
696
+ }
697
+ return more;
698
+ }
699
+
700
+ virtual bool visit_typed_array(const jsoncons::span<const double>& s,
701
+ semantic_tag tag,
702
+ const ser_context& context,
703
+ std::error_code& ec)
704
+ {
705
+ bool more = begin_array(s.size(), tag,context, ec);
706
+ for (auto p = s.begin(); more && p != s.end(); ++p)
707
+ {
708
+ more = double_value(*p,semantic_tag::none,context, ec);
709
+ }
710
+ if (more)
711
+ {
712
+ more = end_array(context, ec);
713
+ }
714
+ return more;
715
+ }
716
+
717
+ virtual bool visit_begin_multi_dim(const jsoncons::span<const size_t>& shape,
718
+ semantic_tag tag,
719
+ const ser_context& context,
720
+ std::error_code& ec)
721
+ {
722
+ bool more = visit_begin_array(2, tag, context, ec);
723
+ if (more)
724
+ {
725
+ more = visit_begin_array(shape.size(), tag, context, ec);
726
+ for (auto it = shape.begin(); more && it != shape.end(); ++it)
727
+ {
728
+ visit_uint64(*it, semantic_tag::none, context, ec);
729
+ }
730
+ if (more)
731
+ {
732
+ more = visit_end_array(context, ec);
733
+ }
734
+ }
735
+ return more;
736
+ }
737
+
738
+ virtual bool visit_end_multi_dim(const ser_context& context,
739
+ std::error_code& ec)
740
+ {
741
+ return visit_end_array(context, ec);
742
+ }
743
+ };
744
+
745
+ template <class CharT, class Allocator>
746
+ class basic_json_visitor2_to_visitor_adaptor : public basic_json_visitor2<CharT>
747
+ {
748
+ public:
749
+ using typename basic_json_visitor2<CharT>::char_type;
750
+ using typename basic_json_visitor2<CharT>::string_view_type;
751
+ private:
752
+ using char_allocator_type = typename std::allocator_traits<Allocator>:: template rebind_alloc<char_type>;
753
+
754
+ using string_type = std::basic_string<char_type,std::char_traits<char_type>,char_allocator_type>;
755
+
756
+ enum class container_t {root, array, object};
757
+ enum class target_t {destination, buffer};
758
+
759
+ struct level
760
+ {
761
+ private:
762
+ target_t state_;
763
+ container_t type_;
764
+ int even_odd_;
765
+ std::size_t count_;
766
+ public:
767
+
768
+ level(target_t state, container_t type) noexcept
769
+ : state_(state), type_(type), even_odd_(type == container_t::object ? 0 : 1), count_(0)
770
+ {
771
+ }
772
+
773
+ void advance()
774
+ {
775
+ if (!is_key())
776
+ {
777
+ ++count_;
778
+ }
779
+ if (is_object())
780
+ {
781
+ even_odd_ = !even_odd_;
782
+ }
783
+ }
784
+
785
+ bool is_key() const
786
+ {
787
+ return even_odd_ == 0;
788
+ }
789
+
790
+ bool is_object() const
791
+ {
792
+ return type_ == container_t::object;
793
+ }
794
+
795
+ target_t target() const
796
+ {
797
+ return state_;
798
+ }
799
+
800
+ std::size_t count() const
801
+ {
802
+ return count_;
803
+ }
804
+ };
805
+ using level_allocator_type = typename std::allocator_traits<Allocator>:: template rebind_alloc<level>;
806
+
807
+ basic_default_json_visitor<char_type> default_visitor_;
808
+ basic_json_visitor<char_type>* destination_;
809
+ string_type key_;
810
+ string_type key_buffer_;
811
+ std::vector<level,level_allocator_type> level_stack_;
812
+
813
+ const std::basic_string<char> null_constant = {'n','u','l','l'};
814
+ const std::basic_string<char> true_constant = { 't','r','u','e' };
815
+ const std::basic_string<char> false_constant = { 'f', 'a', 'l', 's', 'e' };
816
+
817
+ // noncopyable and nonmoveable
818
+ basic_json_visitor2_to_visitor_adaptor(const basic_json_visitor2_to_visitor_adaptor&) = delete;
819
+ basic_json_visitor2_to_visitor_adaptor& operator=(const basic_json_visitor2_to_visitor_adaptor&) = delete;
820
+ public:
821
+ explicit basic_json_visitor2_to_visitor_adaptor(const Allocator& alloc = Allocator())
822
+ : default_visitor_(), destination_(std::addressof(default_visitor_)),
823
+ key_(alloc), key_buffer_(alloc), level_stack_(alloc)
824
+ {
825
+ level_stack_.emplace_back(target_t::destination,container_t::root); // root
826
+ }
827
+
828
+ explicit basic_json_visitor2_to_visitor_adaptor(basic_json_visitor<char_type>& visitor,
829
+ const Allocator& alloc = Allocator())
830
+ : destination_(std::addressof(visitor)),
831
+ key_(alloc), key_buffer_(alloc), level_stack_(alloc)
832
+ {
833
+ level_stack_.emplace_back(target_t::destination,container_t::root); // root
834
+ }
835
+
836
+ void reset()
837
+ {
838
+ key_.clear();
839
+ key_buffer_.clear();
840
+ level_stack_.clear();
841
+ level_stack_.emplace_back(target_t::destination,container_t::root); // root
842
+ }
843
+
844
+ basic_json_visitor<char_type>& destination()
845
+ {
846
+ return *destination_;
847
+ }
848
+
849
+ void destination(basic_json_visitor<char_type>& dest)
850
+ {
851
+ destination_ = std::addressof(dest);
852
+ }
853
+
854
+ private:
855
+ void visit_flush() override
856
+ {
857
+ destination_->flush();
858
+ }
859
+
860
+ bool visit_begin_object(semantic_tag tag, const ser_context& context, std::error_code& ec) override
861
+ {
862
+ if (level_stack_.back().is_key())
863
+ {
864
+ if (level_stack_.back().target() == target_t::buffer && level_stack_.back().count() > 0)
865
+ {
866
+ key_buffer_.push_back(',');
867
+ }
868
+ level_stack_.emplace_back(target_t::buffer, container_t::object);
869
+ key_buffer_.push_back('{');
870
+ return true;
871
+ }
872
+ else
873
+ {
874
+ switch (level_stack_.back().target())
875
+ {
876
+ case target_t::buffer:
877
+ level_stack_.emplace_back(target_t::buffer, container_t::object);
878
+ key_buffer_.push_back('{');
879
+ return true;
880
+ default:
881
+ level_stack_.emplace_back(target_t::destination, container_t::object);
882
+ return destination_->begin_object(tag, context, ec);
883
+ }
884
+ }
885
+ }
886
+
887
+ bool visit_begin_object(std::size_t length, semantic_tag tag, const ser_context& context, std::error_code& ec) override
888
+ {
889
+ if (level_stack_.back().is_key())
890
+ {
891
+ if (level_stack_.back().target() == target_t::buffer && level_stack_.back().count() > 0)
892
+ {
893
+ key_buffer_.push_back(',');
894
+ }
895
+ level_stack_.emplace_back(target_t::buffer, container_t::object);
896
+ key_buffer_.push_back('{');
897
+ return true;
898
+ }
899
+ else
900
+ {
901
+ switch (level_stack_.back().target())
902
+ {
903
+ case target_t::buffer:
904
+ if (!level_stack_.back().is_object() && level_stack_.back().count() > 0)
905
+ {
906
+ key_buffer_.push_back(',');
907
+ }
908
+ level_stack_.emplace_back(target_t::buffer, container_t::object);
909
+ key_buffer_.push_back('{');
910
+ return true;
911
+ default:
912
+ level_stack_.emplace_back(target_t::destination, container_t::object);
913
+ return destination_->begin_object(length, tag, context, ec);
914
+ }
915
+ }
916
+ }
917
+
918
+ bool visit_end_object(const ser_context& context, std::error_code& ec) override
919
+ {
920
+ bool retval = true;
921
+ switch (level_stack_.back().target())
922
+ {
923
+ case target_t::buffer:
924
+ key_buffer_.push_back('}');
925
+ JSONCONS_ASSERT(level_stack_.size() > 1);
926
+ level_stack_.pop_back();
927
+
928
+ if (level_stack_.back().target() == target_t::destination)
929
+ {
930
+ retval = destination_->key(key_buffer_,context, ec);
931
+ key_buffer_.clear();
932
+ }
933
+ else if (level_stack_.back().is_key())
934
+ {
935
+ key_buffer_.push_back(':');
936
+ }
937
+ level_stack_.back().advance();
938
+ break;
939
+ default:
940
+ JSONCONS_ASSERT(level_stack_.size() > 1);
941
+ level_stack_.pop_back();
942
+ level_stack_.back().advance();
943
+ retval = destination_->end_object(context, ec);
944
+ break;
945
+ }
946
+ return retval;
947
+ }
948
+
949
+ bool visit_begin_array(semantic_tag tag, const ser_context& context, std::error_code& ec) override
950
+ {
951
+ if (level_stack_.back().is_key())
952
+ {
953
+ if (level_stack_.back().target() == target_t::buffer && level_stack_.back().count() > 0)
954
+ {
955
+ key_buffer_.push_back(',');
956
+ }
957
+ level_stack_.emplace_back(target_t::buffer, container_t::array);
958
+ key_buffer_.push_back('[');
959
+ return true;
960
+ }
961
+ else
962
+ {
963
+ switch (level_stack_.back().target())
964
+ {
965
+ case target_t::buffer:
966
+ if (level_stack_.back().is_object() && level_stack_.back().count() > 0)
967
+ {
968
+ key_buffer_.push_back(',');
969
+ }
970
+ level_stack_.emplace_back(target_t::buffer, container_t::array);
971
+ key_buffer_.push_back('[');
972
+ return true;
973
+ default:
974
+ level_stack_.emplace_back(target_t::destination, container_t::array);
975
+ return destination_->begin_array(tag, context, ec);
976
+ }
977
+ }
978
+ }
979
+
980
+ bool visit_begin_array(std::size_t length, semantic_tag tag, const ser_context& context, std::error_code& ec) override
981
+ {
982
+ if (level_stack_.back().is_key())
983
+ {
984
+ if (level_stack_.back().target() == target_t::buffer && level_stack_.back().count() > 0)
985
+ {
986
+ key_buffer_.push_back(',');
987
+ }
988
+ level_stack_.emplace_back(target_t::buffer, container_t::array);
989
+ key_buffer_.push_back('[');
990
+ return true;
991
+ }
992
+ else
993
+ {
994
+ switch (level_stack_.back().target())
995
+ {
996
+ case target_t::buffer:
997
+ if (!level_stack_.back().is_object() && level_stack_.back().count() > 0)
998
+ {
999
+ key_buffer_.push_back(',');
1000
+ }
1001
+ level_stack_.emplace_back(target_t::buffer, container_t::array);
1002
+ key_buffer_.push_back('[');
1003
+ return true;
1004
+ default:
1005
+ level_stack_.emplace_back(target_t::destination, container_t::array);
1006
+ return destination_->begin_array(length, tag, context, ec);
1007
+ }
1008
+ }
1009
+ }
1010
+
1011
+ bool visit_end_array(const ser_context& context, std::error_code& ec) override
1012
+ {
1013
+ bool retval = true;
1014
+ switch (level_stack_.back().target())
1015
+ {
1016
+ case target_t::buffer:
1017
+ key_buffer_.push_back(']');
1018
+ JSONCONS_ASSERT(level_stack_.size() > 1);
1019
+ level_stack_.pop_back();
1020
+ if (level_stack_.back().target() == target_t::destination)
1021
+ {
1022
+ retval = destination_->key(key_buffer_, context, ec);
1023
+ key_buffer_.clear();
1024
+ }
1025
+ else if (level_stack_.back().is_key())
1026
+ {
1027
+ key_buffer_.push_back(':');
1028
+ }
1029
+ level_stack_.back().advance();
1030
+ break;
1031
+ default:
1032
+ JSONCONS_ASSERT(level_stack_.size() > 1);
1033
+ level_stack_.pop_back();
1034
+ level_stack_.back().advance();
1035
+ retval = destination_->end_array(context, ec);
1036
+ break;
1037
+ }
1038
+ return retval;
1039
+ }
1040
+
1041
+ bool visit_string(const string_view_type& value,
1042
+ semantic_tag tag,
1043
+ const ser_context& context,
1044
+ std::error_code& ec) override
1045
+ {
1046
+ bool retval = true;
1047
+
1048
+ if (level_stack_.back().is_key())
1049
+ {
1050
+ switch (level_stack_.back().target())
1051
+ {
1052
+ case target_t::buffer:
1053
+ if (level_stack_.back().count() > 0)
1054
+ {
1055
+ key_buffer_.push_back(',');
1056
+ }
1057
+ key_buffer_.push_back('\"');
1058
+ key_buffer_.insert(key_buffer_.end(), value.begin(), value.end());
1059
+ key_buffer_.push_back('\"');
1060
+ key_buffer_.push_back(':');
1061
+ retval = true;
1062
+ break;
1063
+ default:
1064
+ retval = destination_->key(value, context, ec);
1065
+ break;
1066
+ }
1067
+ }
1068
+ else
1069
+ {
1070
+ switch (level_stack_.back().target())
1071
+ {
1072
+ case target_t::buffer:
1073
+ if (!level_stack_.back().is_object() && level_stack_.back().count() > 0)
1074
+ {
1075
+ key_buffer_.push_back(',');
1076
+ }
1077
+ key_buffer_.push_back('\"');
1078
+ key_buffer_.insert(key_buffer_.end(), value.begin(), value.end());
1079
+ key_buffer_.push_back('\"');
1080
+ retval = true;
1081
+ break;
1082
+ default:
1083
+ retval = destination_->string_value(value, tag, context, ec);
1084
+ break;
1085
+ }
1086
+ }
1087
+
1088
+ level_stack_.back().advance();
1089
+ return retval;
1090
+ }
1091
+
1092
+ bool visit_byte_string(const byte_string_view& value,
1093
+ semantic_tag tag,
1094
+ const ser_context& context,
1095
+ std::error_code& ec) override
1096
+ {
1097
+ bool retval = true;
1098
+
1099
+ if (level_stack_.back().is_key() || level_stack_.back().target() == target_t::buffer)
1100
+ {
1101
+ key_.clear();
1102
+ switch (tag)
1103
+ {
1104
+ case semantic_tag::base64:
1105
+ encode_base64(value.begin(), value.end(), key_);
1106
+ break;
1107
+ case semantic_tag::base16:
1108
+ encode_base16(value.begin(), value.end(),key_);
1109
+ break;
1110
+ default:
1111
+ encode_base64url(value.begin(), value.end(),key_);
1112
+ break;
1113
+ }
1114
+ }
1115
+
1116
+ if (level_stack_.back().is_key())
1117
+ {
1118
+ switch (level_stack_.back().target())
1119
+ {
1120
+ case target_t::buffer:
1121
+ if (level_stack_.back().count() > 0)
1122
+ {
1123
+ key_buffer_.push_back(',');
1124
+ }
1125
+ key_buffer_.push_back('\"');
1126
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1127
+ key_buffer_.push_back('\"');
1128
+ key_buffer_.push_back(':');
1129
+ retval = true;
1130
+ break;
1131
+ default:
1132
+ retval = destination_->key(key_, context, ec);
1133
+ break;
1134
+ }
1135
+ }
1136
+ else
1137
+ {
1138
+ switch (level_stack_.back().target())
1139
+ {
1140
+ case target_t::buffer:
1141
+ if (!level_stack_.back().is_object() && level_stack_.back().count() > 0)
1142
+ {
1143
+ key_buffer_.push_back(',');
1144
+ }
1145
+ key_buffer_.push_back('\"');
1146
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1147
+ key_buffer_.push_back('\"');
1148
+ retval = true;
1149
+ break;
1150
+ default:
1151
+ retval = destination_->byte_string_value(value, tag, context, ec);
1152
+ break;
1153
+ }
1154
+ }
1155
+
1156
+ level_stack_.back().advance();
1157
+ return retval;
1158
+ }
1159
+
1160
+ bool visit_byte_string(const byte_string_view& value,
1161
+ uint64_t ext_tag,
1162
+ const ser_context& context,
1163
+ std::error_code& ec) override
1164
+ {
1165
+ bool retval = true;
1166
+
1167
+ if (level_stack_.back().is_key() || level_stack_.back().target() == target_t::buffer)
1168
+ {
1169
+ key_.clear();
1170
+ encode_base64url(value.begin(), value.end(),key_);
1171
+ }
1172
+
1173
+ if (level_stack_.back().is_key())
1174
+ {
1175
+ switch (level_stack_.back().target())
1176
+ {
1177
+ case target_t::buffer:
1178
+ if (level_stack_.back().count() > 0)
1179
+ {
1180
+ key_buffer_.push_back(',');
1181
+ }
1182
+ key_buffer_.push_back('\"');
1183
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1184
+ key_buffer_.push_back('\"');
1185
+ key_buffer_.push_back(':');
1186
+ retval = true;
1187
+ break;
1188
+ default:
1189
+ retval = destination_->key(key_, context, ec);
1190
+ break;
1191
+ }
1192
+ }
1193
+ else
1194
+ {
1195
+ switch (level_stack_.back().target())
1196
+ {
1197
+ case target_t::buffer:
1198
+ if (!level_stack_.back().is_object() && level_stack_.back().count() > 0)
1199
+ {
1200
+ key_buffer_.push_back(',');
1201
+ }
1202
+ key_buffer_.push_back('\"');
1203
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1204
+ key_buffer_.push_back('\"');
1205
+ retval = true;
1206
+ break;
1207
+ default:
1208
+ retval = destination_->byte_string_value(value, ext_tag, context, ec);
1209
+ break;
1210
+ }
1211
+ }
1212
+
1213
+ level_stack_.back().advance();
1214
+ return retval;
1215
+ }
1216
+
1217
+ bool visit_uint64(uint64_t value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1218
+ {
1219
+ bool retval = true;
1220
+
1221
+ if (level_stack_.back().is_key() || level_stack_.back().target() == target_t::buffer)
1222
+ {
1223
+ key_.clear();
1224
+ jsoncons::detail::from_integer(value,key_);
1225
+ }
1226
+
1227
+ if (level_stack_.back().is_key())
1228
+ {
1229
+ switch (level_stack_.back().target())
1230
+ {
1231
+ case target_t::buffer:
1232
+ if (level_stack_.back().count() > 0)
1233
+ {
1234
+ key_buffer_.push_back(',');
1235
+ }
1236
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1237
+ key_buffer_.push_back(':');
1238
+ retval = true;
1239
+ break;
1240
+ default:
1241
+ retval = destination_->key(key_, context, ec);
1242
+ break;
1243
+ }
1244
+ }
1245
+ else
1246
+ {
1247
+ switch (level_stack_.back().target())
1248
+ {
1249
+ case target_t::buffer:
1250
+ if (!level_stack_.back().is_object() && level_stack_.back().count() > 0)
1251
+ {
1252
+ key_buffer_.push_back(',');
1253
+ }
1254
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1255
+ retval = true;
1256
+ break;
1257
+ default:
1258
+ retval = destination_->uint64_value(value, tag, context, ec);
1259
+ break;
1260
+ }
1261
+ }
1262
+
1263
+ level_stack_.back().advance();
1264
+ return retval;
1265
+ }
1266
+
1267
+ bool visit_int64(int64_t value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1268
+ {
1269
+ bool retval = true;
1270
+
1271
+ if (level_stack_.back().is_key() || level_stack_.back().target() == target_t::buffer)
1272
+ {
1273
+ key_.clear();
1274
+ jsoncons::detail::from_integer(value,key_);
1275
+ }
1276
+
1277
+ if (level_stack_.back().is_key())
1278
+ {
1279
+ switch (level_stack_.back().target())
1280
+ {
1281
+ case target_t::buffer:
1282
+ if (level_stack_.back().count() > 0)
1283
+ {
1284
+ key_buffer_.push_back(',');
1285
+ }
1286
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1287
+ key_buffer_.push_back(':');
1288
+ retval = true;
1289
+ break;
1290
+ default:
1291
+ retval = destination_->key(key_, context, ec);
1292
+ break;
1293
+ }
1294
+ }
1295
+ else
1296
+ {
1297
+ switch (level_stack_.back().target())
1298
+ {
1299
+ case target_t::buffer:
1300
+ if (!level_stack_.back().is_object() && level_stack_.back().count() > 0)
1301
+ {
1302
+ key_buffer_.push_back(',');
1303
+ }
1304
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1305
+ retval = true;
1306
+ break;
1307
+ default:
1308
+ retval = destination_->int64_value(value, tag, context, ec);
1309
+ break;
1310
+ }
1311
+ }
1312
+
1313
+ level_stack_.back().advance();
1314
+ return retval;
1315
+ }
1316
+
1317
+ bool visit_half(uint16_t value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1318
+ {
1319
+ bool retval = true;
1320
+
1321
+ if (level_stack_.back().is_key() || level_stack_.back().target() == target_t::buffer)
1322
+ {
1323
+ key_.clear();
1324
+ jsoncons::string_sink<string_type> sink(key_);
1325
+ jsoncons::detail::write_double f{float_chars_format::general,0};
1326
+ double x = binary::decode_half(value);
1327
+ f(x, sink);
1328
+ }
1329
+
1330
+ if (level_stack_.back().is_key())
1331
+ {
1332
+ switch (level_stack_.back().target())
1333
+ {
1334
+ case target_t::buffer:
1335
+ if (level_stack_.back().count() > 0)
1336
+ {
1337
+ key_buffer_.push_back(',');
1338
+ }
1339
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1340
+ key_buffer_.push_back(':');
1341
+ retval = true;
1342
+ break;
1343
+ default:
1344
+ retval = destination_->key(key_, context, ec);
1345
+ break;
1346
+ }
1347
+ }
1348
+ else
1349
+ {
1350
+ switch (level_stack_.back().target())
1351
+ {
1352
+ case target_t::buffer:
1353
+ if (!level_stack_.back().is_object() && level_stack_.back().count() > 0)
1354
+ {
1355
+ key_buffer_.push_back(',');
1356
+ }
1357
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1358
+ retval = true;
1359
+ break;
1360
+ default:
1361
+ retval = destination_->half_value(value, tag, context, ec);
1362
+ break;
1363
+ }
1364
+ }
1365
+
1366
+ level_stack_.back().advance();
1367
+ return retval;
1368
+ }
1369
+
1370
+ bool visit_double(double value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1371
+ {
1372
+ bool retval = true;
1373
+
1374
+ if (level_stack_.back().is_key() || level_stack_.back().target() == target_t::buffer)
1375
+ {
1376
+ key_.clear();
1377
+ string_sink<string_type> sink(key_);
1378
+ jsoncons::detail::write_double f{float_chars_format::general,0};
1379
+ f(value, sink);
1380
+ }
1381
+
1382
+ if (level_stack_.back().is_key())
1383
+ {
1384
+ switch (level_stack_.back().target())
1385
+ {
1386
+ case target_t::buffer:
1387
+ if (level_stack_.back().count() > 0)
1388
+ {
1389
+ key_buffer_.push_back(',');
1390
+ }
1391
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1392
+ key_buffer_.push_back(':');
1393
+ retval = true;
1394
+ break;
1395
+ default:
1396
+ retval = destination_->key(key_, context, ec);
1397
+ break;
1398
+ }
1399
+ }
1400
+ else
1401
+ {
1402
+ switch (level_stack_.back().target())
1403
+ {
1404
+ case target_t::buffer:
1405
+ if (!level_stack_.back().is_object() && level_stack_.back().count() > 0)
1406
+ {
1407
+ key_buffer_.push_back(',');
1408
+ }
1409
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1410
+ retval = true;
1411
+ break;
1412
+ default:
1413
+ retval = destination_->double_value(value, tag, context, ec);
1414
+ break;
1415
+ }
1416
+ }
1417
+
1418
+ level_stack_.back().advance();
1419
+ return retval;
1420
+ }
1421
+
1422
+ bool visit_bool(bool value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1423
+ {
1424
+ bool retval = true;
1425
+
1426
+ if (level_stack_.back().is_key() || level_stack_.back().target() == target_t::buffer)
1427
+ {
1428
+ key_ = value ? true_constant : false_constant;
1429
+ }
1430
+
1431
+ if (level_stack_.back().is_key())
1432
+ {
1433
+ switch (level_stack_.back().target())
1434
+ {
1435
+ case target_t::buffer:
1436
+ if (level_stack_.back().count() > 0)
1437
+ {
1438
+ key_buffer_.push_back(',');
1439
+ }
1440
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1441
+ key_buffer_.push_back(':');
1442
+ retval = true;
1443
+ break;
1444
+ default:
1445
+ retval = destination_->key(key_, context, ec);
1446
+ break;
1447
+ }
1448
+ }
1449
+ else
1450
+ {
1451
+ switch (level_stack_.back().target())
1452
+ {
1453
+ case target_t::buffer:
1454
+ if (!level_stack_.back().is_object() && level_stack_.back().count() > 0)
1455
+ {
1456
+ key_buffer_.push_back(',');
1457
+ }
1458
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1459
+ retval = true;
1460
+ break;
1461
+ default:
1462
+ retval = destination_->bool_value(value, tag, context, ec);
1463
+ break;
1464
+ }
1465
+ }
1466
+
1467
+ level_stack_.back().advance();
1468
+ return retval;
1469
+ }
1470
+
1471
+ bool visit_null(semantic_tag tag, const ser_context& context, std::error_code& ec) override
1472
+ {
1473
+ bool retval = true;
1474
+
1475
+ if (level_stack_.back().is_key() || level_stack_.back().target() == target_t::buffer)
1476
+ {
1477
+ key_ = null_constant;
1478
+ }
1479
+
1480
+ if (level_stack_.back().is_key())
1481
+ {
1482
+ switch (level_stack_.back().target())
1483
+ {
1484
+ case target_t::buffer:
1485
+ if (level_stack_.back().count() > 0)
1486
+ {
1487
+ key_buffer_.push_back(',');
1488
+ }
1489
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1490
+ key_buffer_.push_back(':');
1491
+ retval = true;
1492
+ break;
1493
+ default:
1494
+ retval = destination_->key(key_, context, ec);
1495
+ break;
1496
+ }
1497
+ }
1498
+ else
1499
+ {
1500
+ switch (level_stack_.back().target())
1501
+ {
1502
+ case target_t::buffer:
1503
+ if (!level_stack_.back().is_object() && level_stack_.back().count() > 0)
1504
+ {
1505
+ key_buffer_.push_back(',');
1506
+ }
1507
+ key_buffer_.insert(key_buffer_.end(), key_.begin(), key_.end());
1508
+ retval = true;
1509
+ break;
1510
+ default:
1511
+ retval = destination_->null_value(tag, context, ec);
1512
+ break;
1513
+ }
1514
+ }
1515
+
1516
+ level_stack_.back().advance();
1517
+ return retval;
1518
+ }
1519
+
1520
+ bool visit_typed_array(const jsoncons::span<const uint8_t>& s,
1521
+ semantic_tag tag,
1522
+ const ser_context& context,
1523
+ std::error_code& ec) override
1524
+ {
1525
+ bool is_key = level_stack_.back().is_key();
1526
+ level_stack_.back().advance();
1527
+
1528
+ if (is_key || level_stack_.back().target() == target_t::buffer)
1529
+ {
1530
+ return basic_json_visitor2<CharT>::visit_typed_array(s,tag,context,ec);
1531
+ }
1532
+ else
1533
+ {
1534
+ return destination_->typed_array(s, tag, context, ec);
1535
+ }
1536
+ }
1537
+
1538
+ bool visit_typed_array(const jsoncons::span<const uint16_t>& s,
1539
+ semantic_tag tag,
1540
+ const ser_context& context,
1541
+ std::error_code& ec) override
1542
+ {
1543
+ bool is_key = level_stack_.back().is_key();
1544
+ level_stack_.back().advance();
1545
+
1546
+ if (is_key || level_stack_.back().target() == target_t::buffer)
1547
+ {
1548
+ return basic_json_visitor2<CharT>::visit_typed_array(s,tag,context,ec);
1549
+ }
1550
+ else
1551
+ {
1552
+ return destination_->typed_array(s, tag, context, ec);
1553
+ }
1554
+ }
1555
+
1556
+ bool visit_typed_array(const jsoncons::span<const uint32_t>& s,
1557
+ semantic_tag tag,
1558
+ const ser_context& context,
1559
+ std::error_code& ec) override
1560
+ {
1561
+ bool is_key = level_stack_.back().is_key();
1562
+ level_stack_.back().advance();
1563
+
1564
+ if (is_key || level_stack_.back().target() == target_t::buffer)
1565
+ {
1566
+ return basic_json_visitor2<CharT>::visit_typed_array(s,tag,context,ec);
1567
+ }
1568
+ else
1569
+ {
1570
+ return destination_->typed_array(s, tag, context, ec);
1571
+ }
1572
+ }
1573
+
1574
+ bool visit_typed_array(const jsoncons::span<const uint64_t>& s,
1575
+ semantic_tag tag,
1576
+ const ser_context& context,
1577
+ std::error_code& ec) override
1578
+ {
1579
+ bool is_key = level_stack_.back().is_key();
1580
+ level_stack_.back().advance();
1581
+
1582
+ if (is_key || level_stack_.back().target() == target_t::buffer)
1583
+ {
1584
+ return basic_json_visitor2<CharT>::visit_typed_array(s,tag,context,ec);
1585
+ }
1586
+ else
1587
+ {
1588
+ return destination_->typed_array(s, tag, context, ec);
1589
+ }
1590
+ }
1591
+
1592
+ bool visit_typed_array(const jsoncons::span<const int8_t>& s,
1593
+ semantic_tag tag,
1594
+ const ser_context& context,
1595
+ std::error_code& ec) override
1596
+ {
1597
+ bool is_key = level_stack_.back().is_key();
1598
+ level_stack_.back().advance();
1599
+
1600
+ if (is_key || level_stack_.back().target() == target_t::buffer)
1601
+ {
1602
+ return basic_json_visitor2<CharT>::visit_typed_array(s,tag,context,ec);
1603
+ }
1604
+ else
1605
+ {
1606
+ return destination_->typed_array(s, tag, context, ec);
1607
+ }
1608
+ }
1609
+
1610
+ bool visit_typed_array(const jsoncons::span<const int16_t>& s,
1611
+ semantic_tag tag,
1612
+ const ser_context& context,
1613
+ std::error_code& ec) override
1614
+ {
1615
+ bool is_key = level_stack_.back().is_key();
1616
+ level_stack_.back().advance();
1617
+
1618
+ if (is_key || level_stack_.back().target() == target_t::buffer)
1619
+ {
1620
+ return basic_json_visitor2<CharT>::visit_typed_array(s,tag,context,ec);
1621
+ }
1622
+ else
1623
+ {
1624
+ return destination_->typed_array(s, tag, context, ec);
1625
+ }
1626
+ }
1627
+
1628
+ bool visit_typed_array(const jsoncons::span<const int32_t>& s,
1629
+ semantic_tag tag,
1630
+ const ser_context& context,
1631
+ std::error_code& ec) override
1632
+ {
1633
+ bool is_key = level_stack_.back().is_key();
1634
+ level_stack_.back().advance();
1635
+
1636
+ if (is_key || level_stack_.back().target() == target_t::buffer)
1637
+ {
1638
+ return basic_json_visitor2<CharT>::visit_typed_array(s,tag,context,ec);
1639
+ }
1640
+ else
1641
+ {
1642
+ return destination_->typed_array(s, tag, context, ec);
1643
+ }
1644
+ }
1645
+
1646
+ bool visit_typed_array(const jsoncons::span<const int64_t>& s,
1647
+ semantic_tag tag,
1648
+ const ser_context& context,
1649
+ std::error_code& ec) override
1650
+ {
1651
+ bool is_key = level_stack_.back().is_key();
1652
+ level_stack_.back().advance();
1653
+
1654
+ if (is_key || level_stack_.back().target() == target_t::buffer)
1655
+ {
1656
+ return basic_json_visitor2<CharT>::visit_typed_array(s,tag,context,ec);
1657
+ }
1658
+ else
1659
+ {
1660
+ return destination_->typed_array(s, tag, context, ec);
1661
+ }
1662
+ }
1663
+
1664
+ bool visit_typed_array(half_arg_t,
1665
+ const jsoncons::span<const uint16_t>& s,
1666
+ semantic_tag tag,
1667
+ const ser_context& context,
1668
+ std::error_code& ec) override
1669
+ {
1670
+ bool is_key = level_stack_.back().is_key();
1671
+ level_stack_.back().advance();
1672
+
1673
+ if (is_key || level_stack_.back().target() == target_t::buffer)
1674
+ {
1675
+ return basic_json_visitor2<CharT>::visit_typed_array(half_arg,s,tag,context,ec);
1676
+ }
1677
+ else
1678
+ {
1679
+ return destination_->typed_array(half_arg, s, tag, context, ec);
1680
+ }
1681
+ }
1682
+
1683
+ bool visit_typed_array(const jsoncons::span<const float>& s,
1684
+ semantic_tag tag,
1685
+ const ser_context& context,
1686
+ std::error_code& ec) override
1687
+ {
1688
+ bool is_key = level_stack_.back().is_key();
1689
+ level_stack_.back().advance();
1690
+
1691
+ if (is_key || level_stack_.back().target() == target_t::buffer)
1692
+ {
1693
+ return basic_json_visitor2<CharT>::visit_typed_array(s,tag,context,ec);
1694
+ }
1695
+ else
1696
+ {
1697
+ return destination_->typed_array(s, tag, context, ec);
1698
+ }
1699
+ }
1700
+
1701
+ bool visit_typed_array(const jsoncons::span<const double>& s,
1702
+ semantic_tag tag,
1703
+ const ser_context& context,
1704
+ std::error_code& ec) override
1705
+ {
1706
+ bool is_key = level_stack_.back().is_key();
1707
+ level_stack_.back().advance();
1708
+
1709
+ if (is_key || level_stack_.back().target() == target_t::buffer)
1710
+ {
1711
+ return basic_json_visitor2<CharT>::visit_typed_array(s,tag,context,ec);
1712
+ }
1713
+ else
1714
+ {
1715
+ return destination_->typed_array(s, tag, context, ec);
1716
+ }
1717
+ }
1718
+ };
1719
+
1720
+ template <class CharT>
1721
+ class basic_default_json_visitor2 : public basic_json_visitor2<CharT>
1722
+ {
1723
+ bool parse_more_;
1724
+ std::error_code ec_;
1725
+ public:
1726
+ using typename basic_json_visitor2<CharT>::string_view_type;
1727
+
1728
+ basic_default_json_visitor2(bool accept_more = true,
1729
+ std::error_code ec = std::error_code())
1730
+ : parse_more_(accept_more), ec_(ec)
1731
+ {
1732
+ }
1733
+ private:
1734
+ void visit_flush() override
1735
+ {
1736
+ }
1737
+
1738
+ bool visit_begin_object(semantic_tag, const ser_context&, std::error_code& ec) override
1739
+ {
1740
+ if (ec_)
1741
+ {
1742
+ ec = ec_;
1743
+ }
1744
+ return parse_more_;
1745
+ }
1746
+
1747
+ bool visit_begin_object(std::size_t, semantic_tag, const ser_context&, std::error_code& ec) override
1748
+ {
1749
+ if (ec_)
1750
+ {
1751
+ ec = ec_;
1752
+ }
1753
+ return parse_more_;
1754
+ }
1755
+
1756
+ bool visit_end_object(const ser_context&, std::error_code& ec) override
1757
+ {
1758
+ if (ec_)
1759
+ {
1760
+ ec = ec_;
1761
+ }
1762
+ return parse_more_;
1763
+ }
1764
+
1765
+ bool visit_begin_array(semantic_tag, const ser_context&, std::error_code& ec) override
1766
+ {
1767
+ if (ec_)
1768
+ {
1769
+ ec = ec_;
1770
+ }
1771
+ return parse_more_;
1772
+ }
1773
+
1774
+ bool visit_begin_array(std::size_t, semantic_tag, const ser_context&, std::error_code& ec) override
1775
+ {
1776
+ if (ec_)
1777
+ {
1778
+ ec = ec_;
1779
+ }
1780
+ return parse_more_;
1781
+ }
1782
+
1783
+ bool visit_end_array(const ser_context&, std::error_code& ec) override
1784
+ {
1785
+ if (ec_)
1786
+ {
1787
+ ec = ec_;
1788
+ }
1789
+ return parse_more_;
1790
+ }
1791
+
1792
+ bool visit_null(semantic_tag, const ser_context&, std::error_code& ec) override
1793
+ {
1794
+ if (ec_)
1795
+ {
1796
+ ec = ec_;
1797
+ }
1798
+ return parse_more_;
1799
+ }
1800
+
1801
+ bool visit_string(const string_view_type&, semantic_tag, const ser_context&, std::error_code& ec) override
1802
+ {
1803
+ if (ec_)
1804
+ {
1805
+ ec = ec_;
1806
+ }
1807
+ return parse_more_;
1808
+ }
1809
+
1810
+ bool visit_byte_string(const byte_string_view&, semantic_tag, const ser_context&, std::error_code& ec) override
1811
+ {
1812
+ if (ec_)
1813
+ {
1814
+ ec = ec_;
1815
+ }
1816
+ return parse_more_;
1817
+ }
1818
+
1819
+ bool visit_uint64(uint64_t, semantic_tag, const ser_context&, std::error_code& ec) override
1820
+ {
1821
+ if (ec_)
1822
+ {
1823
+ ec = ec_;
1824
+ }
1825
+ return parse_more_;
1826
+ }
1827
+
1828
+ bool visit_int64(int64_t, semantic_tag, const ser_context&, std::error_code& ec) override
1829
+ {
1830
+ if (ec_)
1831
+ {
1832
+ ec = ec_;
1833
+ }
1834
+ return parse_more_;
1835
+ }
1836
+
1837
+ bool visit_half(uint16_t, semantic_tag, const ser_context&, std::error_code& ec) override
1838
+ {
1839
+ if (ec_)
1840
+ {
1841
+ ec = ec_;
1842
+ }
1843
+ return parse_more_;
1844
+ }
1845
+
1846
+ bool visit_double(double, semantic_tag, const ser_context&, std::error_code& ec) override
1847
+ {
1848
+ if (ec_)
1849
+ {
1850
+ ec = ec_;
1851
+ }
1852
+ return parse_more_;
1853
+ }
1854
+
1855
+ bool visit_bool(bool, semantic_tag, const ser_context&, std::error_code& ec) override
1856
+ {
1857
+ if (ec_)
1858
+ {
1859
+ ec = ec_;
1860
+ }
1861
+ return parse_more_;
1862
+ }
1863
+ };
1864
+
1865
+ // basic_json_visitor_to_visitor2_adaptor
1866
+
1867
+ template <class CharT>
1868
+ class basic_json_visitor_to_visitor2_adaptor : public basic_json_visitor<CharT>
1869
+ {
1870
+ public:
1871
+ using typename basic_json_visitor<CharT>::char_type;
1872
+ using typename basic_json_visitor<CharT>::string_view_type;
1873
+ private:
1874
+ basic_json_visitor2<char_type>& destination_;
1875
+
1876
+ // noncopyable and nonmoveable
1877
+ basic_json_visitor_to_visitor2_adaptor(const basic_json_visitor_to_visitor2_adaptor&) = delete;
1878
+ basic_json_visitor_to_visitor2_adaptor& operator=(const basic_json_visitor_to_visitor2_adaptor&) = delete;
1879
+ public:
1880
+ basic_json_visitor_to_visitor2_adaptor(basic_json_visitor2<char_type>& visitor)
1881
+ : destination_(visitor)
1882
+ {
1883
+ }
1884
+
1885
+ basic_json_visitor2<char_type>& destination()
1886
+ {
1887
+ return destination_;
1888
+ }
1889
+
1890
+ private:
1891
+ void visit_flush() override
1892
+ {
1893
+ destination_.flush();
1894
+ }
1895
+
1896
+ bool visit_begin_object(semantic_tag tag, const ser_context& context, std::error_code& ec) override
1897
+ {
1898
+ return destination_.begin_object(tag, context, ec);
1899
+ }
1900
+
1901
+ bool visit_begin_object(std::size_t length, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1902
+ {
1903
+ return destination_.begin_object(length, tag, context, ec);
1904
+ }
1905
+
1906
+ bool visit_end_object(const ser_context& context, std::error_code& ec) override
1907
+ {
1908
+ return destination_.end_object(context, ec);
1909
+ }
1910
+
1911
+ bool visit_begin_array(semantic_tag tag, const ser_context& context, std::error_code& ec) override
1912
+ {
1913
+ return destination_.begin_array(tag, context, ec);
1914
+ }
1915
+
1916
+ bool visit_begin_array(std::size_t length, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1917
+ {
1918
+ return destination_.begin_array(length, tag, context, ec);
1919
+ }
1920
+
1921
+ bool visit_end_array(const ser_context& context, std::error_code& ec) override
1922
+ {
1923
+ return destination_.end_array(context, ec);
1924
+ }
1925
+
1926
+ bool visit_key(const string_view_type& name,
1927
+ const ser_context& context,
1928
+ std::error_code& ec) override
1929
+ {
1930
+ return destination_.visit_string(name, context, ec);
1931
+ }
1932
+
1933
+ bool visit_string(const string_view_type& value,
1934
+ semantic_tag tag,
1935
+ const ser_context& context,
1936
+ std::error_code& ec) override
1937
+ {
1938
+ return destination_.string_value(value, tag, context, ec);
1939
+ }
1940
+
1941
+ bool visit_byte_string(const byte_string_view& b,
1942
+ semantic_tag tag,
1943
+ const ser_context& context,
1944
+ std::error_code& ec) override
1945
+ {
1946
+ return destination_.byte_string_value(b, tag, context, ec);
1947
+ }
1948
+
1949
+ bool visit_uint64(uint64_t value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1950
+ {
1951
+ return destination_.uint64_value(value, tag, context, ec);
1952
+ }
1953
+
1954
+ bool visit_int64(int64_t value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1955
+ {
1956
+ return destination_.int64_value(value, tag, context, ec);
1957
+ }
1958
+
1959
+ bool visit_half(uint16_t value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1960
+ {
1961
+ return destination_.half_value(value, tag, context, ec);
1962
+ }
1963
+
1964
+ bool visit_double(double value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1965
+ {
1966
+ return destination_.double_value(value, tag, context, ec);
1967
+ }
1968
+
1969
+ bool visit_bool(bool value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
1970
+ {
1971
+ return destination_.bool_value(value, tag, context, ec);
1972
+ }
1973
+
1974
+ bool visit_null(semantic_tag tag, const ser_context& context, std::error_code& ec) override
1975
+ {
1976
+ return destination_.null_value(tag, context, ec);
1977
+ }
1978
+ };
1979
+
1980
+ class diagnostics_visitor2 : public basic_default_json_visitor2<char>
1981
+ {
1982
+ bool visit_begin_object(semantic_tag, const ser_context&, std::error_code&) override
1983
+ {
1984
+ std::cout << "visit_begin_object" << std::endl;
1985
+ return true;
1986
+ }
1987
+
1988
+ bool visit_begin_object(std::size_t length, semantic_tag, const ser_context&, std::error_code&) override
1989
+ {
1990
+ std::cout << "visit_begin_object " << length << std::endl;
1991
+ return true;
1992
+ }
1993
+
1994
+ bool visit_end_object(const ser_context&, std::error_code&) override
1995
+ {
1996
+ std::cout << "visit_end_object" << std::endl;
1997
+ return true;
1998
+ }
1999
+
2000
+ bool visit_begin_array(semantic_tag, const ser_context&, std::error_code&) override
2001
+ {
2002
+ std::cout << "visit_begin_array" << std::endl;
2003
+ return true;
2004
+ }
2005
+
2006
+ bool visit_begin_array(std::size_t length, semantic_tag, const ser_context&, std::error_code&) override
2007
+ {
2008
+ std::cout << "visit_begin_array " << length << std::endl;
2009
+ return true;
2010
+ }
2011
+
2012
+ bool visit_end_array(const ser_context&, std::error_code&) override
2013
+ {
2014
+ std::cout << "visit_end_array" << std::endl;
2015
+ return true;
2016
+ }
2017
+
2018
+ bool visit_string(const string_view_type& s, semantic_tag, const ser_context&, std::error_code&) override
2019
+ {
2020
+ std::cout << "visit_string " << s << std::endl;
2021
+ return true;
2022
+ }
2023
+ bool visit_int64(int64_t val, semantic_tag, const ser_context&, std::error_code&) override
2024
+ {
2025
+ std::cout << "visit_int64 " << val << std::endl;
2026
+ return true;
2027
+ }
2028
+ bool visit_uint64(uint64_t val, semantic_tag, const ser_context&, std::error_code&) override
2029
+ {
2030
+ std::cout << "visit_uint64 " << val << std::endl;
2031
+ return true;
2032
+ }
2033
+ bool visit_bool(bool val, semantic_tag, const ser_context&, std::error_code&) override
2034
+ {
2035
+ std::cout << "visit_bool " << val << std::endl;
2036
+ return true;
2037
+ }
2038
+ bool visit_null(semantic_tag, const ser_context&, std::error_code&) override
2039
+ {
2040
+ std::cout << "visit_null " << std::endl;
2041
+ return true;
2042
+ }
2043
+
2044
+ bool visit_typed_array(const jsoncons::span<const uint16_t>& s,
2045
+ semantic_tag tag,
2046
+ const ser_context&,
2047
+ std::error_code&) override
2048
+ {
2049
+ std::cout << "visit_typed_array uint16_t " << tag << std::endl;
2050
+ for (auto val : s)
2051
+ {
2052
+ std::cout << val << "" << std::endl;
2053
+ }
2054
+ std::cout << "" << std::endl;
2055
+ return true;
2056
+ }
2057
+
2058
+ bool visit_typed_array(half_arg_t, const jsoncons::span<const uint16_t>& s,
2059
+ semantic_tag tag,
2060
+ const ser_context&,
2061
+ std::error_code&) override
2062
+ {
2063
+ std::cout << "visit_typed_array half_arg_t uint16_t " << tag << "" << std::endl;
2064
+ for (auto val : s)
2065
+ {
2066
+ std::cout << val << "" << std::endl;
2067
+ }
2068
+ std::cout << "" << std::endl;
2069
+ return true;
2070
+ }
2071
+ };
2072
+
2073
+ using json_visitor2 = basic_json_visitor2<char>;
2074
+ using default_json_visitor2 = basic_default_json_visitor2<char>;
2075
+ using json_visitor2_to_visitor_adaptor = basic_json_visitor2_to_visitor_adaptor<char>;
2076
+
2077
+ } // namespace jsoncons
2078
+
2079
+ #endif