25#ifndef JOIN_DATA_JSON_HPP
26#define JOIN_DATA_JSON_HPP
29#include <dconv/probe.hpp>
30#include <dconv/atod.hpp>
31#include <dconv/dtoa.hpp>
58 "00010203040506070809"
59 "10111213141516171819"
60 "20212223242526272829"
61 "30313233343536373839"
62 "40414243444546474849"
63 "50515253545556575859"
64 "60616263646566676869"
65 "70717273747576777879"
66 "80818283848586878889"
67 "90919293949596979899"};
76 for (
int i = 0; i < 32; ++i)
80 data[
static_cast<unsigned char> (
'\b')] =
'b';
81 data[
static_cast<unsigned char> (
'\t')] =
't';
82 data[
static_cast<unsigned char> (
'\n')] =
'n';
83 data[
static_cast<unsigned char> (
'\f')] =
'f';
84 data[
static_cast<unsigned char> (
'\r')] =
'r';
85 data[
static_cast<unsigned char> (
'"')] =
'"';
86 data[
static_cast<unsigned char> (
'\\')] =
'\\';
99 for (
unsigned i = 0; i < 0x20; ++i)
103 data[
static_cast<unsigned char> (
'"')] = 1;
104 data[
static_cast<unsigned char> (
'\\')] = 1;
117 data[
static_cast<unsigned char> (
'\t')] = 1;
118 data[
static_cast<unsigned char> (
'\n')] = 1;
119 data[
static_cast<unsigned char> (
'\r')] = 1;
120 data[
static_cast<unsigned char> (
' ')] = 1;
156 virtual const char*
name ()
const noexcept;
163 virtual std::string
message (
int code)
const;
198 template <JsonWriteMode WriteMode = JsonWriteMode::None>
208 :
_out (document.rdbuf ())
333 template <JsonWriteMode Mode = WriteMode>
339 memcpy (&bits, &value,
sizeof (bits));
340 const bool neg = (bits >> 63) != 0;
341 const uint64_t exp = (bits >> 52) & 0x7FFULL;
342 const uint64_t frac = bits & 0x000FFFFFFFFFFFFFULL;
378 template <JsonWriteMode Mode = WriteMode>
383 if (std::isfinite (value))
385 if ((std::trunc (value) == value) && (value >= 0) &&
386 (value <
static_cast<double> (std::numeric_limits<uint64_t>::max ())))
390 else if ((std::trunc (value) == value) &&
391 (value >=
static_cast<double> (std::numeric_limits<int64_t>::min ())) &&
392 (value <
static_cast<double> (std::numeric_limits<int64_t>::max ())))
502 template <JsonWriteMode Mode = WriteMode>
514 template <JsonWriteMode Mode = WriteMode>
515 std::vector<std::reference_wrapper<const Member>>
members (
const Object&
object)
const
518 std::vector<std::reference_wrapper<const Member>> sorted (
object.begin (),
object.end ());
519 std::sort (sorted.begin (), sorted.end (), [] (
const Member& a,
const Member& b) {
520 if (!a.first.isString () || !b.first.isString ())
522 return !a.first.isString () && b.first.isString ();
524 std::string_view sa = a.
first.getString ();
525 std::string_view sb = b.
first.getString ();
527 sb.data () + sb.size ()) < 0;
656 return setKey (std::string_view (
key));
688 _out->sputn (_buffer, _size);
710 if (value == std::numeric_limits<int32_t>::min ())
713 writeUint64 (
static_cast<uint64_t
> (std::numeric_limits<int32_t>::max ()) + 1);
720 writeUint64 (
static_cast<uint64_t
> (-value));
724 writeUint64 (
static_cast<uint64_t
> (value));
733 writeUint64 (
static_cast<uint64_t
> (value));
742 if (value == std::numeric_limits<int64_t>::min ())
745 writeUint64 (
static_cast<uint64_t
> (std::numeric_limits<int64_t>::max ()) + 1);
752 writeUint64 (
static_cast<uint64_t
> (-value));
756 writeUint64 (
static_cast<uint64_t
> (value));
765 static constexpr uint64_t pow10[20] = {1ULL,
781 10000000000000000ULL,
782 100000000000000000ULL,
783 1000000000000000000ULL,
784 10000000000000000000ULL};
786 uint64_t high = value / 100000000;
787 uint64_t top = high / 100000000;
788 uint32_t mid =
static_cast<uint32_t
> (high - top * 100000000);
789 uint32_t low =
static_cast<uint32_t
> (value - high * 100000000);
803 size_t length = ((64 - __builtin_clzll (value | 1)) * 1233) >> 12;
804 length += (value >= pow10[length]) + (value == 0);
806 appendDigits (buffer + 20 - length, length);
818 char* end = dconv::dtoa (buf, value);
819 for (
char* pos = buf; pos < end; ++pos)
822 if ((*pos ==
'e') && (*(pos + 1) !=
'-'))
834 _size = dconv::dtoa (_buffer + _size, value) - _buffer;
844 const char* cur = value.data ();
845 const char* end = cur + value.size ();
849 const char* beg = cur;
851 while (end - cur >= 8)
853 uint64_t word, quote, backslash;
854 std::memcpy (&word, cur, 8);
855 quote = word ^ 0x2222222222222222ULL;
856 backslash = word ^ 0x5C5C5C5C5C5C5C5CULL;
857 uint64_t mask = (((quote - 0x0101010101010101ULL) & ~quote) |
858 ((backslash - 0x0101010101010101ULL) & ~backslash) |
859 ((word - 0x2020202020202020ULL) & ~word)) &
860 0x8080808080808080ULL;
863 cur += __builtin_ctzll (mask) >> 3;
876 append (beg, cur - beg);
884 uint8_t ch =
static_cast<uint8_t
> (*cur);
893 char escapeSeq[2] = {
'\\',
static_cast<char> (esc)};
894 append (escapeSeq, 2);
911 _buffer[_size++] = data;
919 inline void append (
const char* data, uint32_t size)
924 if (size >=
sizeof (_buffer))
926 _out->sputn (data, size);
930 std::memcpy (_buffer + _size, data, size);
945 std::memcpy (_buffer + _size, digits, 20);
954 if (_depth && !_first)
973 static constexpr char spaces[] =
" ";
974 size_t count = _depth * _indentation;
977 size_t n = (count <
sizeof (spaces) - 1) ? count :
sizeof (spaces) - 1;
999 static constexpr char spaces[] =
"\n ";
1000 size_t count = _depth * _indentation;
1003 if (
JOIN_UNLIKELY (
sizeof (_buffer) - _size <
sizeof (spaces) - 1))
1007 std::memcpy (_buffer + _size, spaces,
sizeof (spaces) - 1);
1032 if (_depth && ((_arrays[(_depth - 1) >> 6] >> ((_depth - 1) & 63)) & 1))
1054 char _buffer[1024] = {};
1097 return JsonReadMode (
static_cast<int> (a) &
static_cast<int> (b));
1108 return JsonReadMode (
static_cast<int> (a) |
static_cast<int> (b));
1136 template <JsonReadMode ReadMode = JsonReadMode::None>
1183 template <
typename Handler>
1184 int deserialize (
const char* document,
size_t length, Handler& handler)
1186 dconv::StringProbe in (document, length);
1187 return read (in, handler);
1197 template <
typename Handler>
1198 int deserialize (
const char* first,
const char* last, Handler& handler)
1200 dconv::StringProbe in (first, last);
1201 return read (in, handler);
1210 template <
typename Handler>
1213 dconv::StringProbe in (document.data (), document.size ());
1214 return read (in, handler);
1223 template <
typename Handler>
1226 dconv::StreamProbe in (document);
1227 return read (in, handler);
1236 template <
typename Handler>
1239 dconv::StreamProbe in (document);
1240 return read (in, handler);
1249 template <
typename Handler>
1252 dconv::StreamProbe in (document);
1253 return read (in, handler);
1262 template <
typename Handler>
1265 dconv::StreamProbe in (document);
1266 return read (in, handler);
1275 template <
typename Handler>
1278 dconv::StreamProbe in (document);
1279 return read (in, handler);
1288 template <
typename Handler>
1291 dconv::StreamProbe in (document);
1292 return read (in, handler);
1302 template <
typename ProbeType>
1314 template <
typename ProbeType,
typename Handler>
1315 int read (ProbeType& document, Handler&& handler)
1319 if (
JOIN_LIKELY (readDocument (document, handler) == 0))
1339 template <
typename ProbeType,
typename Handler>
1342 if (skipWhitespaces (document) != 0)
1347 if (readValue (document, handler, 0) != 0)
1352 if (ReadMode & JsonReadMode::StopParsingOnDone)
1357 if (skipWhitespaces (document) != 0)
1362 if (document.peek () != std::char_traits<char>::eof ())
1378 template <
typename ProbeType,
typename Handler>
1379 int readValue (ProbeType& document, Handler& handler,
size_t depth)
1381 int ch = document.peek ();
1386 return readArray (document, handler, depth);
1389 return readObject (document, handler, depth);
1392 return readString (document, handler);
1395 return readNull (document, handler);
1398 return readTrue (document, handler);
1401 return readFalse (document, handler);
1403 return readNumber (document, handler);
1413 template <
typename ProbeType,
typename Handler>
1416 if (
JOIN_UNLIKELY ((document.get () !=
'u') || (document.get () !=
'l') || (document.get () !=
'l')))
1422 return handler.setNull ();
1431 template <
typename ProbeType,
typename Handler>
1434 if (
JOIN_UNLIKELY ((document.get () !=
'r') || (document.get () !=
'u') || (document.get () !=
'e')))
1440 return handler.setBool (
true);
1449 template <
typename ProbeType,
typename Handler>
1452 if (
JOIN_UNLIKELY ((document.get () !=
'a') || (document.get () !=
'l') || (document.get () !=
's') ||
1453 (document.get () !=
'e')))
1459 return handler.setBool (
false);
1468 template <
typename ProbeType,
typename Handler>
1472 uint64_t significand = 0;
1473 int64_t exponent = 0;
1474 bool negative =
false;
1477 if (
JOIN_LIKELY (dconv::atod (document, value, significand, exponent, negative, ec) == 0))
1479 return handler.setDouble (value);
1490 return handler.setUint64 (significand);
1493 if (significand <=
static_cast<uint64_t
> (std::numeric_limits<int64_t>::max ()) + 1)
1495 return handler.setInt64 (
static_cast<int64_t
> (-significand));
1498 return handler.setDouble (-
static_cast<double> (significand));
1507 template <
typename ProbeType>
1508 inline int readHex (ProbeType& document, uint32_t& u)
1510 for (
int i = 0; i < 4; ++i)
1512 char c = document.get ();
1518 else if (isUpperAlpha (c))
1522 else if (isLowerAlpha (c))
1544 template <
typename ProbeType>
1549 if (readHex (document, u) == -1)
1554 char16_t units[2] = {
static_cast<char16_t> (u), 0};
1555 const char16_t* cur = units;
1556 const char16_t* end = units + 1;
1558 if (utf16::isHighSurrogate (u))
1560 if ((document.get () !=
'\\') || (document.get () !=
'u'))
1568 if (readHex (document, v) == -1)
1574 units[1] =
static_cast<char16_t> (v);
1578 if (utf16::decode (cur, end, u) == -1)
1585 output.append (buf, utf8::encode (u, buf));
1596 template <
typename ProbeType>
1599 int ch = document.get ();
1603 output.push_back (
'"');
1606 output.push_back (
'\\');
1609 output.push_back (
'/');
1612 output.push_back (
'\b');
1615 output.push_back (
'\f');
1618 output.push_back (
'\n');
1621 output.push_back (
'\r');
1624 output.push_back (
'\t');
1627 return readUnicode (document, output);
1643 template <
typename ProbeType,
typename Handler>
1644 int readString (ProbeType& document, Handler& handler,
bool isKey =
false)
1646 std::string_view chunk;
1648 if constexpr (std::is_same_v<ProbeType, dconv::StringProbe>)
1650 chunk = readUntilEscaped (document);
1660 return isKey ? handler.setKey (chunk) : handler.setString (chunk);
1664 thread_local std::string cache;
1665 std::string output = std::move (cache);
1666 output.assign (chunk);
1670 size_t pos = output.size ();
1671 readUntilEscaped (document, output);
1673 if (
JOIN_UNLIKELY (validateChunk (std::string_view (output).substr (pos)) == -1))
1678 int ch = document.peek ();
1689 if (readEscaped (document, output) == -1)
1703 int result = isKey ? handler.setKey (output) : handler.setString (output);
1704 cache = std::move (output);
1715 template <
typename ProbeType,
typename Handler>
1734 if (document.getIf (
']'))
1736 return handler.stopArray ();
1741 if (
JOIN_UNLIKELY (readValue (document, handler, depth + 1) == -1))
1746 int ch = document.get ();
1748 if (
JOIN_UNLIKELY (details::whitespaceLookup.data[
static_cast<unsigned char> (ch)]))
1754 ch = document.get ();
1775 return handler.stopArray ();
1785 template <
typename ProbeType,
typename Handler>
1804 if (document.getIf (
'}'))
1806 return handler.stopObject ();
1817 if (
JOIN_UNLIKELY (readString (document, handler,
true) == -1))
1822 if (document.peek () !=
':')
1841 if (
JOIN_UNLIKELY (readValue (document, handler, depth + 1) == -1))
1846 int ch = document.get ();
1848 if (
JOIN_UNLIKELY (details::whitespaceLookup.data[
static_cast<unsigned char> (ch)]))
1854 ch = document.get ();
1875 return handler.stopObject ();
1885 const char* beg = document.tell ();
1886 const char* cur = beg;
1887 const char* end = document.end ();
1889 while (end - cur >= 8)
1891 uint64_t word, quote, backslash;
1892 std::memcpy (&word, cur, 8);
1893 quote = word ^ 0x2222222222222222ULL;
1894 backslash = word ^ 0x5C5C5C5C5C5C5C5CULL;
1896 (((quote - 0x0101010101010101ULL) & ~quote) | ((backslash - 0x0101010101010101ULL) & ~backslash) |
1897 ((word - 0x2020202020202020ULL) & ~word)) &
1898 0x8080808080808080ULL;
1901 cur += __builtin_ctzll (mask) >> 3;
1907 while (cur < end && !details::escapedLookup.data[
static_cast<unsigned char> (*cur)])
1912 document.seek (cur);
1913 return std::string_view (beg,
static_cast<size_t> (cur - beg));
1923 out.append (readUntilEscaped (document));
1934 while ((c = document.peek ()) != std::char_traits<char>::eof () &&
1935 !details::escapedLookup.data[
static_cast<unsigned char> (c)])
1937 out.push_back (
static_cast<char> (c));
1949 if constexpr (ReadMode & JsonReadMode::ParseComments)
1951 return skipWhitespacesAndComments (document);
1954 const char* cur = document.tell ();
1955 const char* end = document.end ();
1957 while (cur < end && details::whitespaceLookup.data[
static_cast<unsigned char> (*cur)])
1961 while (end - cur >= 8)
1964 std::memcpy (&word, cur, 8);
1965 word ^= 0x2020202020202020ULL;
1968 cur += __builtin_ctzll (word) >> 3;
1975 document.seek (cur);
1987 if constexpr (ReadMode & JsonReadMode::ParseComments)
1989 return skipWhitespacesAndComments (document);
1993 while ((c = document.peek ()) != std::char_traits<char>::eof () &&
1994 details::whitespaceLookup.data[
static_cast<unsigned char> (c)])
2009 const char* cur = document.tell ();
2010 const char* end = document.end ();
2014 while (cur < end && details::whitespaceLookup.data[
static_cast<unsigned char> (*cur)])
2019 if (cur >= end || *cur !=
'/')
2032 bool closed =
false;
2035 if (*cur ==
'*' && (cur + 1 < end) && *(cur + 1) ==
'/')
2048 else if (*cur ==
'/')
2051 const char* p =
static_cast<const char*
> (std::memchr (cur,
'\n', end - cur));
2060 document.seek (cur);
2074 while ((c = document.peek ()) != std::char_traits<char>::eof ())
2076 while ((c = document.peek ()) != std::char_traits<char>::eof () &&
2077 details::whitespaceLookup.data[
static_cast<unsigned char> (c)])
2088 c = document.peek ();
2090 if (c == std::char_traits<char>::eof ())
2098 bool closed =
false;
2100 while ((c = document.get ()) != std::char_traits<char>::eof ())
2102 if (c ==
'*' && document.peek () ==
'/')
2119 while ((c = document.get ()) != std::char_traits<char>::eof () && c !=
'\n')
2139 if constexpr (ReadMode & JsonReadMode::ValidateEncoding)
2141 if (
JOIN_UNLIKELY (utf8::validate (chunk.data (), chunk.data () + chunk.size ()) == -1))
2157 return static_cast<unsigned char> (c -
'A') <= 5u;
2167 return static_cast<unsigned char> (c -
'a') <= 5u;
2177 return static_cast<unsigned char> (c -
'0') <= 9u;
2189 struct is_error_condition_enum<
join::JsonErrc> :
public true_type
JSON reader class.
Definition json.hpp:1138
int deserialize(const char *document, size_t length, Handler &handler)
deserialize a document.
Definition json.hpp:1184
constexpr bool isDigit(char c) noexcept
check if digit.
Definition json.hpp:2175
BasicJsonReader()=default
default constructor.
void readUntilEscaped(dconv::StringProbe &document, std::string &out) noexcept
read characters until escaped.
Definition json.hpp:1921
JOIN_ALWAYS_INLINE int readObject(ProbeType &document, Handler &handler, size_t depth)
parse an object value.
Definition json.hpp:1786
int deserialize(std::stringstream &document, Handler &handler)
deserialize a document.
Definition json.hpp:1224
int readFalse(ProbeType &document, Handler &handler)
parse a false value.
Definition json.hpp:1450
int deserialize(std::istringstream &document, Handler &handler)
deserialize a document.
Definition json.hpp:1237
JOIN_ALWAYS_INLINE int readArray(ProbeType &document, Handler &handler, size_t depth)
parse an array value.
Definition json.hpp:1716
int deserialize(std::fstream &document, Handler &handler)
deserialize a document.
Definition json.hpp:1250
int skipWhitespaces(dconv::StreamProbe &document) noexcept
skip whitespaces, and comments when comment parsing is enabled.
Definition json.hpp:1985
int readHex(ProbeType &document, uint32_t &u)
parse a 4-digit hexadecimal sequence..
Definition json.hpp:1508
constexpr bool isLowerAlpha(char c) noexcept
check if lower case alphanumeric character.
Definition json.hpp:2165
int skipWhitespacesAndComments(dconv::StreamProbe &document) noexcept
skip whitespaces and comments.
Definition json.hpp:2070
~BasicJsonReader()=default
destroy instance.
BasicJsonReader(const BasicJsonReader &other)=delete
copy constructor.
constexpr bool isUpperAlpha(char c) noexcept
check if upper case alphanumeric character.
Definition json.hpp:2155
int readNumber(ProbeType &document, Handler &handler)
parse a number value.
Definition json.hpp:1469
int readString(ProbeType &document, Handler &handler, bool isKey=false)
parse a string value.
Definition json.hpp:1644
int skipWhitespacesAndComments(dconv::StringProbe &document) noexcept
skip whitespaces and comments.
Definition json.hpp:2007
int readValue(ProbeType &document, Handler &handler, size_t depth)
parse a JSON value.
Definition json.hpp:1379
int readDocument(ProbeType &document, Handler &handler)
parse a document.
Definition json.hpp:1340
int deserialize(std::iostream &document, Handler &handler)
deserialize a document.
Definition json.hpp:1276
int readNull(ProbeType &document, Handler &handler)
parse a null value.
Definition json.hpp:1414
BasicJsonReader(BasicJsonReader &&other)=delete
move constructor.
std::string_view readUntilEscaped(dconv::StringProbe &document) noexcept
read characters until escaped.
Definition json.hpp:1883
void readUntilEscaped(dconv::StreamProbe &document, std::string &out) noexcept
read characters until escaped.
Definition json.hpp:1931
int readUnicode(ProbeType &document, std::string &output)
parse unicode.
Definition json.hpp:1545
int skipWhitespaces(dconv::StringProbe &document) noexcept
skip whitespaces, and comments when comment parsing is enabled.
Definition json.hpp:1947
int deserialize(std::string_view document, Handler &handler)
deserialize a document.
Definition json.hpp:1211
int readTrue(ProbeType &document, Handler &handler)
parse a true value.
Definition json.hpp:1432
int read(ProbeType &document, Value &value)
parse a document into a value.
Definition json.hpp:1303
int deserialize(std::istream &document, Handler &handler)
deserialize a document.
Definition json.hpp:1289
int deserialize(const char *first, const char *last, Handler &handler)
deserialize a document.
Definition json.hpp:1198
int readEscaped(ProbeType &document, std::string &output)
parse escaped sequence.
Definition json.hpp:1597
int deserialize(std::ifstream &document, Handler &handler)
deserialize a document.
Definition json.hpp:1263
int read(ProbeType &document, Handler &&handler)
parse a document, resetting the handler on failure.
Definition json.hpp:1315
int validateChunk(std::string_view chunk) noexcept
validate the encoding of the last chunk read, when encoding validation is enabled.
Definition json.hpp:2137
JSON writer class.
Definition json.hpp:200
int setKey(bool key)
set boolean key.
Definition json.hpp:549
void space()
write space.
Definition json.hpp:1018
BasicJsonWriter(const BasicJsonWriter &other)=delete
copy constructor.
uint64_t _arrays[saxMaxDepth/64]
array flags of the open containers, one bit per depth.
Definition json.hpp:1060
int setNull()
set null value.
Definition json.hpp:248
int setUint(uint32_t value)
set unsigned integer value.
Definition json.hpp:294
void appendDigits(const char *digits, size_t length)
append the digits of a number, read 20 bytes at a time.
Definition json.hpp:939
const Object & members(const Object &object) const noexcept
get object members in writing order.
Definition json.hpp:503
std::streambuf * _out
underlying output stream.
Definition json.hpp:1051
void endLine()
write end of line.
Definition json.hpp:963
BasicJsonWriter & operator=(const BasicJsonWriter &other)=delete
copy assignment.
void writeEscaped(std::string_view value)
escape string value.
Definition json.hpp:842
int setDouble(double value)
set real value in canonical form.
Definition json.hpp:379
void append(const char *data, uint32_t size)
append data to output stream in batch.
Definition json.hpp:919
~BasicJsonWriter()=default
destroy instance.
int startObject(uint32_t size=0)
start object.
Definition json.hpp:481
void writeDouble(double value)
write real value.
Definition json.hpp:813
int setKey(uint64_t key)
set unsigned 64 bits integer key.
Definition json.hpp:597
void indent()
write indentation.
Definition json.hpp:971
void reset() noexcept
reset the writer state, discarding buffered data.
Definition json.hpp:696
int setDouble(double value)
set real value.
Definition json.hpp:334
BasicJsonWriter(BasicJsonWriter &&other)=delete
move constructor.
int stopArray()
stop array.
Definition json.hpp:458
int setUint64(uint64_t value)
set unsigned 64 bits integer value.
Definition json.hpp:320
int stopObject()
stop object.
Definition json.hpp:663
int startArray(uint32_t size=0)
start array.
Definition json.hpp:438
void newLine()
write end of line and indentation.
Definition json.hpp:986
int setKey(int64_t key)
set 64 bits integer key.
Definition json.hpp:585
void writeUint64(uint64_t value)
write 64 bits unsigned integer value.
Definition json.hpp:763
int setKey(double key)
set real key.
Definition json.hpp:609
void writeUint(uint32_t value)
write unsigned integer value.
Definition json.hpp:731
void writeInt(int32_t value)
write integer value.
Definition json.hpp:708
void flush()
flush buffered data to output stream.
Definition json.hpp:684
int setString(std::string_view value)
set string value.
Definition json.hpp:414
int setKey(std::string_view key)
set string key.
Definition json.hpp:621
int setKey(uint32_t key)
set unsigned integer key.
Definition json.hpp:573
int setBool(bool value)
set boolean value.
Definition json.hpp:261
int setKey(const char *key)
set string key.
Definition json.hpp:654
size_t _depth
number of open containers.
Definition json.hpp:1063
void array()
add comma, go to line and indent if in array.
Definition json.hpp:1029
void comma()
write comma.
Definition json.hpp:952
void writeInt64(int64_t value)
write 64 bits integer value.
Definition json.hpp:740
__attribute__((noinline)) void indentLine()
write end of line and indentation, out of the compact writing path.
Definition json.hpp:997
std::vector< std::reference_wrapper< const Member > > members(const Object &object) const
get object members sorted by key in UTF-16 order.
Definition json.hpp:515
size_t _indentation
indentation.
Definition json.hpp:1066
int setInt64(int64_t value)
set 64 bits integer value.
Definition json.hpp:307
int setInt(int32_t value)
set integer value.
Definition json.hpp:281
void endValue()
mark the end of a value, flushing the document once complete.
Definition json.hpp:1041
int setKey(int32_t key)
set integer key.
Definition json.hpp:561
BasicJsonWriter(std::ostream &document, size_t indentation=0)
create instance.
Definition json.hpp:207
void append(char data)
append character to output stream in batch.
Definition json.hpp:905
bool _first
is first element.
Definition json.hpp:1069
int setKey(std::nullptr_t key)
set null key.
Definition json.hpp:537
JSON error category.
Definition json.hpp:150
virtual std::string message(int code) const
translate JSON error code to human readable error string.
Definition json.cpp:44
virtual const char * name() const noexcept
get JSON error category name.
Definition json.cpp:35
value builder class, filled by balanced SAX calls.
Definition value_builder.hpp:49
value class.
Definition value.hpp:92
const std::string key(65, 'a')
key.
constexpr UnescapedTable unescapedLookup
Definition json.hpp:90
constexpr char digitPairs[201]
Definition json.hpp:57
constexpr char hexDigits[17]
Definition json.hpp:126
constexpr WhitespaceTable whitespaceLookup
Definition json.hpp:124
constexpr EscapedTable escapedLookup
Definition json.hpp:108
int compareUtf16Order(const char *first1, const char *last1, const char *first2, const char *last2) noexcept
compare two UTF-8 inputs in UTF-16 code unit order.
Definition utf8.hpp:314
int validate(const char *first, const char *last) noexcept
validate UTF-8 input.
Definition utf8.hpp:276
Definition acceptor.hpp:32
JsonWriteMode
JSON serialization mode.
Definition json.hpp:190
const std::error_category & jsonCategory() noexcept
get error category.
Definition json.cpp:77
JsonReadMode
JSON deserialization mode.
Definition json.hpp:1082
@ StopParsingOnDone
Definition json.hpp:1086
@ ParseComments
Definition json.hpp:1084
@ ValidateEncoding
Definition json.hpp:1085
@ None
Definition json.hpp:1083
std::error_code make_error_code(join::Errc code) noexcept
Create an std::error_code object.
Definition error.cpp:195
constexpr size_t saxMaxDepth
max number of nested containers.
Definition sax.hpp:42
thread_local std::error_code lastError
last error.
Definition error.cpp:32
std::vector< Member > Object
object.
Definition value.hpp:86
std::error_condition make_error_condition(join::Errc code) noexcept
Create an std::error_condition object.
Definition error.cpp:204
JsonErrc
JSON error codes.
Definition json.hpp:133
member.
Definition value.hpp:60
Type first
member key.
Definition value.hpp:76
uint8_t data[256]
Definition json.hpp:94
constexpr EscapedTable()
Definition json.hpp:96
uint8_t data[256]
Definition json.hpp:71
constexpr UnescapedTable()
Definition json.hpp:73
constexpr WhitespaceTable()
Definition json.hpp:114
uint8_t data[256]
Definition json.hpp:112
#define JOIN_LIKELY(x)
Definition utils.hpp:50
#define JOIN_ALWAYS_INLINE
Definition utils.hpp:48
#define JOIN_UNLIKELY(x)
Definition utils.hpp:51