1 #ifndef SIMDJSON_SERIALIZATION_H
2 #define SIMDJSON_SERIALIZATION_H
4 #include "simdjson/common_defs.h"
5 #include "simdjson/dom/document.h"
6 #include "simdjson/error.h"
7 #include "simdjson/internal/dom_parser_implementation.h"
8 #include "simdjson/internal/tape_ref.h"
9 #include "simdjson/padded_string.h"
10 #include "simdjson/portability.h"
31 template <
class formatter = mini_formatter>
32 class string_builder {
35 string_builder() =
default;
43 simdjson_inline
void clear();
51 simdjson_inline std::string_view str()
const;
63 class mini_formatter {
65 mini_formatter() =
default;
67 simdjson_inline
void comma();
69 simdjson_inline
void start_array();
71 simdjson_inline
void end_array();
73 simdjson_inline
void start_object();
75 simdjson_inline
void end_object();
77 simdjson_inline
void true_atom();
79 simdjson_inline
void false_atom();
81 simdjson_inline
void null_atom();
83 simdjson_inline
void number(int64_t x);
85 simdjson_inline
void number(uint64_t x);
87 simdjson_inline
void number(
double x);
89 simdjson_inline
void key(std::string_view unescaped);
91 simdjson_inline
void string(std::string_view unescaped);
93 simdjson_inline
void clear();
98 simdjson_inline std::string_view str()
const;
103 simdjson_inline
void one_char(
char c);
105 std::vector<char> buffer{};
120 simdjson::internal::string_builder<> sb;
122 return (out << sb.str());
124 #if SIMDJSON_EXCEPTIONS
127 return (out << x.
value());
138 simdjson::internal::string_builder<> sb;
140 return (out << sb.str());
142 #if SIMDJSON_EXCEPTIONS
145 return (out << x.
value());
156 simdjson::internal::string_builder<> sb;
158 return (out << sb.str());
160 #if SIMDJSON_EXCEPTIONS
163 return (out << x.
value());
181 simdjson::internal::string_builder<> sb;
183 std::string_view answer = sb.str();
184 return std::string(answer.data(), answer.size());
186 #if SIMDJSON_EXCEPTIONS
188 std::string
to_string(simdjson_result<T> x) {
189 if (x.error()) {
throw simdjson_error(x.error()); }
207 #if SIMDJSON_EXCEPTIONS
209 std::string
minify(simdjson_result<T> x) {
210 if (x.error()) {
throw simdjson_error(x.error()); }
Key/value pair in an object.
@ number
A JSON number ( 1 or -2.3 or 4.5e6 ...)
We want to support argument-dependent lookup (ADL).
std::ostream & operator<<(std::ostream &out, error_code error) noexcept
Write the error message to the output stream.
std::string to_string(T x)
Converts JSON to a string.
std::string minify(T x)
Minifies a JSON element or document, printing the smallest possible valid JSON.
Exception thrown when an exception-supporting simdjson method is called.
The result of a simdjson operation that could fail.
simdjson_inline error_code error() const noexcept
The error.
simdjson_inline T & value() &noexcept(false)
Get the result value.