-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqc-json-decode.hpp
919 lines (803 loc) · 29.5 KB
/
qc-json-decode.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
#pragma once
///
/// QC JSON 2.0.2
///
/// Quick and clean JSON5 header library for C++20
///
/// Austin Quick : 2019 - 2022
///
/// https://github.com/daskie/qc-json
///
/// This standalone header provides a SAX interface for decoding JSON5
///
/// See the README for more info and examples!
///
#include <cctype>
#include <charconv>
#include <limits>
#include <stdexcept>
#include <string>
#include <string_view>
#include <system_error>
#include <utility>
#ifndef QC_JSON_COMMON
#define QC_JSON_COMMON
namespace qc::json
{
using std::string;
using std::string_view;
using namespace std::string_literals;
using namespace std::string_view_literals;
using uchar = unsigned char;
///
/// Common exception type used for all `qc::json` exceptions
///
struct Error : std::runtime_error
{
explicit Error(const string_view msg = {}) noexcept :
std::runtime_error(msg.data())
{}
};
///
/// Simple enum representing a json container type
///
enum class Container : int8_t
{
none,
object,
array
};
///
/// Pass with an object or array to specify its density
///
enum class Density : int8_t
{
unspecified = 0b000, /// Use that of the root or parent element
multiline = 0b001, /// Elements are put on new lines
uniline = 0b011, /// Elements are put on one line separated by spaces
nospace = 0b111 /// No whitespace is used whatsoever
};
}
#endif // QC_JSON_COMMON
namespace qc::json
{
///
/// This will be thrown if anything goes wrong during the decoding process
///
struct DecodeError : Error
{
size_t position; /// The index into the string where the error occurred
DecodeError(const string_view msg, size_t position) noexcept;
};
///
/// Decodes the JSON string
///
/// A note on numbers:
///
/// A number will be parsed and sent to the composer as either a `int64_t`, a `uint64_t`, or a `double`
/// - `int64_t` if the number is an integer (a fractional component of zero is okay) and can fit in a `int64_t`
/// - `uint64_t` if the number is a positive integer, can fit in a `uint64_t`, but cannot fit in a `int64_t`
/// - `double` if the number has a non-zero fractional component, has an exponent, or is an integer that is too large to fit in a `int64_t` or `uint64_t`
///
/// @param json the string to decode
/// @param composer the contents of the JSON are decoded in order and passed to this to do something with
/// @param initialState the initial state object to be passed to the composer
///
template <typename Composer, typename State> void decode(string_view json, Composer & composer, State & initialState);
template <typename Composer, typename State> void decode(string_view json, Composer & composer, State && initialState);
///
/// An example composer whose operations are all no-ops
///
/// Any custom composer must provide matching methods. This class may be extended for baseline no-ops
///
template <typename State = nullptr_t>
class DummyComposer
{
public: //--------------------------------------------------------------
State object(State & /*outerState*/) { return State{}; }
State array(State & /*outerState*/) { return State{}; }
void end(const Density /*density*/, State && /*innerState*/, State & /*outerState*/) {}
void key(const std::string_view /*key*/, State & /*state*/) {}
void val(const std::string_view /*val*/, State & /*state*/) {}
void val(const int64_t /*val*/, State & /*state*/) {}
void val(const uint64_t /*val*/, State & /*state*/) {}
void val(const double /*val*/, State & /*state*/) {}
void val(const bool /*val*/, State & /*state*/) {}
void val(const std::nullptr_t, State & /*state*/) {}
void comment(const std::string_view /*comment*/, State & /*state*/) {}
};
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace qc::json
{
inline Density & operator&=(Density & d1, const Density d2) noexcept
{
reinterpret_cast<uint8_t &>(d1) &= uint8_t(int8_t(d2));
return d1;
}
inline Density & operator|=(Density & d1, const Density d2) noexcept
{
reinterpret_cast<uint8_t &>(d1) |= uint8_t(int8_t(d2));
return d1;
}
// This functionality is wrapped in a class purely as a convenient way to keep track of state
template <typename Composer, typename State>
class _Decoder
{
public: //--------------------------------------------------------------
_Decoder(const string_view str, Composer & composer) :
_start{str.data()},
_end{_start + str.length()},
_pos{_start},
_composer{composer}
{}
void operator()(State & initialState)
{
_skipSpaceAndIngestComments(initialState);
_ingestValue(initialState);
_skipSpaceAndIngestComments(initialState);
// Allow trailing comma
if (_tryConsumeChar(','))
{
_skipSpaceAndIngestComments(initialState);
}
if (_pos != _end)
{
throw DecodeError{"Extraneous content"sv, size_t(_pos - _start)};
}
}
private: //-------------------------------------------------------------
const char * const _start{nullptr};
const char * const _end{nullptr};
const char * _pos{nullptr};
size_t _line{0u};
size_t _column{0u};
Composer & _composer;
string _stringBuffer{};
Density _skipWhitespace()
{
Density density{Density::nospace};
while (_pos < _end)
{
if (std::isspace(uchar(*_pos)))
{
if (*_pos == '\n') density &= Density::multiline;
else density &= Density::uniline;
++_pos;
}
else
{
break;
}
}
return density;
}
Density _ingestLineComment(bool concat, State & state)
{
// We already know we have `//`
_pos += 2;
const char * commentStart{_pos};
// Seek to end of line
while (_pos < _end && *_pos != '\n')
{
++_pos;
}
const char * commentEnd{_pos};
// Trim space after `//`
if (commentStart < commentEnd && *commentStart == ' ')
{
++commentStart;
}
// Trim `\r` from end
if (commentEnd[-1] == '\r')
{
--commentEnd;
}
// If this is a continuation, add it to the buffer
if (concat)
{
_stringBuffer.push_back('\n');
_stringBuffer.append(commentStart, commentEnd);
}
// Check for continuation on next line
bool isContinuation{false};
Density density{Density::nospace};
// This comment ended with a newline (as opposed to the end of the json)
if (_pos < _end)
{
// Skip newline
++_pos;
density = Density::multiline;
// There are no additional newlines
if (_skipWhitespace() > Density::multiline)
{
isContinuation = _pos + 2 < _end && _pos[0] == '/' && _pos[1] == '/';
}
}
// There is more comment to come
if (isContinuation)
{
if (!concat)
{
_stringBuffer.assign(commentStart, commentEnd);
}
_ingestLineComment(true, state);
if (!concat)
{
_composer.comment(string_view{_stringBuffer}, state);
}
}
// This is the end of the comment
else
{
if (!concat)
{
_composer.comment(string_view{commentStart, size_t(commentEnd - commentStart)}, state);
}
}
return density;
}
void _ingestBlockComment(State & state)
{
// We already know we have `/*`
_pos += 2;
const char * commentStart{_pos};
// Seek to `*/`
while (_pos + 1 < _end && !(_pos[0] == '*' && _pos[1] == '/'))
{
++_pos;
}
// If `*/` found
if (_pos + 1 < _end)
{
const char * commentEnd{_pos};
_pos += 2;
// Trim space after `/*`
if (*commentStart == ' ')
{
++commentStart;
}
// Trim space before `*/`
if (commentEnd > commentStart && commentEnd[-1] == ' ')
{
--commentEnd;
}
_composer.comment(string_view{commentStart, size_t(commentEnd - commentStart)}, state);
}
else
{
throw DecodeError{"Block comment is unterminated"sv, size_t(commentStart - 2 - _start)};
}
}
Density _skipSpaceAndIngestComments(State & state)
{
// Skip whitespace
Density density{_skipWhitespace()};
while (true)
{
// Check for comment
if (_pos + 1 < _end && _pos[0] == '/')
{
// Ingest line comment
if (_pos[1] == '/')
{
density &= _ingestLineComment(false, state);
// `_ingesetLineComment` skips trailing whitespace already
continue;
}
// Ingest block comment
else if (_pos[1] == '*')
{
_ingestBlockComment(state);
// Skip whitespace
density &= _skipWhitespace();
continue;
}
}
break;
}
return density;
}
bool _tryConsumeChar(const char c)
{
if (_pos < _end && *_pos == c)
{
++_pos;
return true;
}
else
{
return false;
}
}
void _consumeChar(const char c)
{
if (!_tryConsumeChar(c))
{
throw DecodeError{("Expected `"s += c) += '`', size_t(_pos - _start)};
}
}
bool _tryConsumeChars(const string_view str)
{
if (size_t(_end - _pos) >= str.length())
{
for (size_t i{0u}; i < str.length(); ++i)
{
if (_pos[i] != str[i])
{
return false;
}
}
_pos += str.length();
return true;
}
else
{
return false;
}
}
void _consumeChars(const string_view str)
{
if (!_tryConsumeChars(str))
{
throw DecodeError{("Expected `"s += str) += '`', size_t(_pos - _start)};
}
}
void _ingestValue(State & state)
{
if (_pos >= _end)
{
throw DecodeError{"Expected value"sv, size_t(_pos - _start)};
}
char c{*_pos};
// First check for typical easy values
switch (c)
{
case '{':
{
_ingestObject(state);
return;
}
case '[':
{
_ingestArray(state);
return;
}
case '"':
{
_ingestString('"', state);
return;
}
case '\'':
{
_ingestString('\'', state);
return;
}
}
// Now determine whether there is a +/- sign to narrow it down to numbers or not
const int sign{(c == '+') - (c == '-')};
if (sign)
{
// There was a sign, so we'll keep track of that and increment our position
++_pos;
if (_pos >= _end)
{
throw DecodeError{"Expected number"sv, size_t(_pos - _start)};
}
c = *_pos;
}
else
{
// There was no sign, so we can check the non-number keywords
if (_tryConsumeChars("true"sv))
{
_composer.val(true, state);
return;
}
else if (_tryConsumeChars("false"sv))
{
_composer.val(false, state);
return;
}
else if (_tryConsumeChars("null"sv))
{
_composer.val(nullptr, state);
return;
}
}
// At this point, we know it is a number (or invalid)
if (std::isdigit(uchar(c)) || (c == '.' && _pos + 1 < _end && std::isdigit(_pos[1])))
{
_ingestNumber(sign, state);
return;
}
else if (_tryConsumeChars("nan"sv) || _tryConsumeChars("NaN"sv))
{
_composer.val(std::numeric_limits<double>::quiet_NaN(), state);
return;
}
else if (_tryConsumeChars("inf"sv) || _tryConsumeChars("Infinity"sv))
{
_composer.val(sign < 0 ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity(), state);
return;
}
// Nothing matched, throw an error
throw DecodeError{"Unknown value"sv, size_t(_pos - _start)};
}
void _ingestObject(State & outerState)
{
State innerState{_composer.object(outerState)};
++_pos; // We already know we have `{`
Density density{_skipSpaceAndIngestComments(innerState)};
if (!_tryConsumeChar('}'))
{
while (true)
{
// Parse key
if (_pos >= _end)
{
throw DecodeError{"Expected key"sv, size_t(_pos - _start)};
}
const char c{*_pos};
const string_view key{(c == '"' || c == '\'') ? _consumeString(c) : _consumeIdentifier()};
_composer.key(key, innerState);
density &= _skipSpaceAndIngestComments(innerState);
_consumeChar(':');
density &= _skipSpaceAndIngestComments(innerState);
_ingestValue(innerState);
density &= _skipSpaceAndIngestComments(innerState);
if (_tryConsumeChar('}'))
{
break;
}
else
{
_consumeChar(',');
density &= _skipSpaceAndIngestComments(innerState);
// Allow trailing comma
if (_tryConsumeChar('}'))
{
break;
}
}
}
}
_composer.end(density, std::move(innerState), outerState);
}
void _ingestArray(State & outerState)
{
State innerState{_composer.array(outerState)};
++_pos; // We already know we have `[`
Density density{_skipSpaceAndIngestComments(innerState)};
if (!_tryConsumeChar(']'))
{
while (true)
{
_ingestValue(innerState);
density &= _skipSpaceAndIngestComments(innerState);
if (_tryConsumeChar(']'))
{
break;
}
else
{
_consumeChar(',');
density &= _skipSpaceAndIngestComments(innerState);
// Allow trailing comma
if (_tryConsumeChar(']'))
{
break;
}
}
}
}
_composer.end(density, std::move(innerState), outerState);
}
void _ingestString(const char quote, State & state)
{
_composer.val(_consumeString(quote), state);
}
string_view _consumeString(const char quote)
{
_stringBuffer.clear();
++_pos; // We already know we have `"` or `'`
while (true)
{
if (_pos >= _end)
{
throw DecodeError{"Expected end quote"sv, size_t(_pos - _start)};
}
const char c{*_pos};
if (c == quote)
{
++_pos;
return _stringBuffer;
}
else if (c == '\\')
{
++_pos;
// Check for escaped newline
if (*_pos == '\n')
{
++_pos;
}
else if (*_pos == '\r' && _pos + 1 < _end && _pos[1] == '\n')
{
_pos += 2;
}
else
{
_stringBuffer.push_back(_consumeEscaped());
}
}
else if (std::isprint(uchar(c)))
{
_stringBuffer.push_back(c);
++_pos;
}
else
{
throw DecodeError{"Invalid string content"sv, size_t(_pos - _start)};
}
}
}
char _consumeEscaped()
{
if (_pos >= _end)
{
throw DecodeError{"Expected escape sequence"sv, size_t(_pos - _start)};
}
const char c{*_pos};
++_pos;
switch (c)
{
case '0': return '\0';
case 'b': return '\b';
case 't': return '\t';
case 'n': return '\n';
case 'v': return '\v';
case 'f': return '\f';
case 'r': return '\r';
case 'x': return _consumeCodePoint(2);
case 'u': return _consumeCodePoint(4);
case 'U': return _consumeCodePoint(8);
default:
if (std::isprint(uchar(c)))
{
return c;
}
else
{
throw DecodeError{"Invalid escape sequence"sv, size_t(_pos - _start - 1)};
}
}
}
char _consumeCodePoint(const int digits)
{
if (_end - _pos < digits)
{
throw DecodeError{("Expected "s += std::to_string(digits)) += " code point digits"sv, size_t(_pos - _start)};
}
uint32_t val;
const std::from_chars_result res{std::from_chars(_pos, _pos + digits, val, 16)};
if (res.ec != std::errc{})
{
throw DecodeError{"Invalid code point"sv, size_t(_pos - _start)};
}
_pos += digits;
return char(val);
}
string_view _consumeIdentifier()
{
_stringBuffer.clear();
// Ensure identifier is at least one character long
char c{*_pos};
if (std::isalnum(uchar(c)) || c == '_')
{
_stringBuffer.push_back(c);
++_pos;
}
else
{
throw DecodeError{"Expected identifier"sv, size_t(_pos - _start)};
}
while (true)
{
if (_pos >= _end)
{
return _stringBuffer;
}
c = *_pos;
if (std::isalnum(uchar(c)) || c == '_')
{
_stringBuffer.push_back(c);
++_pos;
}
else
{
return _stringBuffer;
}
}
}
// Returns the string length of the number, including trailing decimal point & zeroes, or `0` if it's not an integer
size_t _isInteger() const
{
const char * pos{_pos};
// Skip all leading digits
while (pos < _end && std::isdigit(uchar(*pos))) ++pos;
// If that's it, we're an integer
if (pos >= _end)
{
return size_t(pos - _pos);
}
// If instead there is a decimal point...
else if (*pos == '.')
{
++pos;
// Skip all zeroes
while (pos < _end && *pos == '0') ++pos;
// If there's a digit or an exponent, we must be a floater
if (pos < _end && (std::isdigit(uchar(*pos)) || *pos == 'e' || *pos == 'E'))
{
return 0;
}
// Otherwise, we're an integer
else
{
return size_t(pos - _pos);
}
}
// If instead there is an exponent, we must be a floater
else if (*pos == 'e' || *pos == 'E')
{
return 0;
}
// Otherwise, that's the end of the number, and we're an integer
else
{
return size_t(pos - _pos);
}
}
void _ingestNumber(const int sign, State & state)
{
// Check if hex/octal/binary
if (*_pos == '0' && _pos + 1 < _end)
{
int base{0};
switch (_pos[1])
{
case 'x': case 'X': base = 16; break;
case 'o': case 'O': base = 8; break;
case 'b': case 'B': base = 2; break;
}
if (base)
{
if (sign)
{
throw DecodeError{"Hex, octal, and binary numbers must not be signed"sv, size_t(_pos - _start)};
}
_pos += 2;
_ingestHexOctalBinary(base, state);
return;
}
}
// Determine if integer or floater
if (size_t length{_isInteger()}; length)
{
if (sign < 0)
{
_ingestInteger<true>(length, state);
}
else
{
_ingestInteger<false>(length, state);
}
}
else
{
_ingestFloater(sign < 0, state);
}
}
void _ingestHexOctalBinary(const int base, State & state)
{
uint64_t val;
const std::from_chars_result res{std::from_chars(_pos, _end, val, base)};
// There was an issue parsing
if (res.ec != std::errc{})
{
throw DecodeError{base == 2 ? "Invalid binary"sv : base == 8 ? "Invalid octal"sv : "Invalid hex"sv, size_t(_pos - _start)};
}
_pos = res.ptr;
_composer.val(val, state);
}
template <bool negative>
void _ingestInteger(const size_t length, State & state)
{
std::conditional_t<negative, int64_t, uint64_t> val;
// Edge case that `.0` should evaluate to the integer `0`
if (*_pos == '.')
{
val = 0;
}
else
{
const std::from_chars_result res{std::from_chars(_pos - negative, _end, val)};
// There was an issue parsing
if (res.ec != std::errc{})
{
// If too large, parse as a floater instead
if (res.ec == std::errc::result_out_of_range)
{
_ingestFloater(negative, state);
return;
}
// Some other issue
else
{
throw DecodeError{"Invalid integer"sv, size_t(_pos - _start)};
}
}
}
_pos += length;
// If unsigned and the most significant bit is not set, we default to reporting it as signed
if constexpr (!negative)
{
if (!(val & 0x8000000000000000u))
{
_composer.val(int64_t(val), state);
return;
}
}
_composer.val(val, state);
}
void _ingestFloater(const bool negative, State & state)
{
double val;
const std::from_chars_result res{std::from_chars(_pos - negative, _end, val)};
// There was an issue parsing
if (res.ec != std::errc{})
{
throw DecodeError{"Invalid floater"sv, size_t(_pos - _start)};
}
_pos = res.ptr;
_composer.val(val, state);
}
};
inline DecodeError::DecodeError(const string_view msg, const size_t position) noexcept :
Error{msg},
position{position}
{}
template <typename Composer, typename State> concept _ComposerHasObjectMethod = requires (Composer composer, State state) { State{composer.object(state)}; };
template <typename Composer, typename State> concept _ComposerHasArrayMethod = requires (Composer composer, State state) { State{composer.array(state)}; };
template <typename Composer, typename State> concept _ComposerHasEndMethod = requires (Composer composer, const Density density, State innerState, State outerState) { composer.end(density, std::move(innerState), outerState); };
template <typename Composer, typename State> concept _ComposerHasKeyMethod = requires (Composer composer, const std::string_view key, State state) { composer.key(key, state); };
template <typename Composer, typename State> concept _ComposerHasStringValMethod = requires (Composer composer, const std::string_view val, State state) { composer.val(val, state); };
template <typename Composer, typename State> concept _ComposerHasSignedIntegerValMethod = requires (Composer composer, const int64_t val, State state) { composer.val(val, state); };
template <typename Composer, typename State> concept _ComposerHasUnsignedIntegerValMethod = requires (Composer composer, const uint64_t val, State state) { composer.val(val, state); };
template <typename Composer, typename State> concept _ComposerHasFloaterValMethod = requires (Composer composer, const double val, State state) { composer.val(val, state); };
template <typename Composer, typename State> concept _ComposerHasBooleanValMethod = requires (Composer composer, const bool val, State state) { composer.val(val, state); };
template <typename Composer, typename State> concept _ComposerHasNullValMethod = requires (Composer composer, State state) { composer.val(nullptr, state); };
template <typename Composer, typename State> concept _ComposerHasCommentMethod = requires (Composer composer, const string_view comment, State state) { composer.comment(comment, state); };
template <typename Composer, typename State>
inline void decode(string_view json, Composer & composer, State & initialState)
{
// Much more understandable compile errors than just letting the template code fly
static_assert(_ComposerHasObjectMethod<Composer, State>);
static_assert(_ComposerHasArrayMethod<Composer, State>);
static_assert(_ComposerHasEndMethod<Composer, State>);
static_assert(_ComposerHasKeyMethod<Composer, State>);
static_assert(_ComposerHasStringValMethod<Composer, State>);
static_assert(_ComposerHasSignedIntegerValMethod<Composer, State>);
static_assert(_ComposerHasUnsignedIntegerValMethod<Composer, State>);
static_assert(_ComposerHasFloaterValMethod<Composer, State>);
static_assert(_ComposerHasBooleanValMethod<Composer, State>);
static_assert(_ComposerHasNullValMethod<Composer, State>);
static_assert(_ComposerHasCommentMethod<Composer, State>);
return _Decoder<Composer, State>{json, composer}(initialState);
}
template <typename Composer, typename State>
inline void decode(string_view json, Composer & composer, State && initialState)
{
return decode(json, composer, initialState);
}
}