1 #ifndef SIMDJSON_GENERIC_ONDEMAND_SERIALIZATION_INL_H
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_ONDEMAND_SERIALIZATION_INL_H
5 #include "simdjson/generic/ondemand/base.h"
6 #include "simdjson/generic/ondemand/array.h"
7 #include "simdjson/generic/ondemand/document-inl.h"
8 #include "simdjson/generic/ondemand/json_type.h"
9 #include "simdjson/generic/ondemand/object.h"
10 #include "simdjson/generic/ondemand/serialization.h"
11 #include "simdjson/generic/ondemand/value.h"
16 inline std::string_view trim(
const std::string_view str) noexcept {
18 size_t first = str.find_first_not_of(
" \t\n\r");
21 if (std::string_view::npos == first) {
return std::string_view(); }
22 size_t last = str.find_last_not_of(
" \t\n\r");
23 return str.substr(first, (last - first + 1));
29 auto error = x.raw_json().get(v);
30 if(error) {
return error; }
34 inline simdjson_result<std::string_view>
to_json_string(SIMDJSON_IMPLEMENTATION::ondemand::document_reference& x) noexcept {
36 auto error = x.raw_json().get(v);
37 if(error) {
return error; }
48 using namespace SIMDJSON_IMPLEMENTATION::ondemand;
50 auto error = x.type().get(t);
51 if(error !=
SUCCESS) {
return error; }
57 error = x.get_array().get(array);
58 if(error) {
return error; }
64 error = x.get_object().get(
object);
65 if(error) {
return error; }
69 return trim(x.raw_json_token());
75 auto error = x.raw_json().get(v);
76 if(error) {
return error; }
82 auto error = x.raw_json().get(v);
83 if(error) {
return error; }
87 inline simdjson_result<std::string_view>
to_json_string(simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> x) {
88 if (x.error()) {
return x.error(); }
92 inline simdjson_result<std::string_view>
to_json_string(simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference> x) {
93 if (x.error()) {
return x.error(); }
97 inline simdjson_result<std::string_view>
to_json_string(simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> x) {
98 if (x.error()) {
return x.error(); }
102 inline simdjson_result<std::string_view>
to_json_string(simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> x) {
103 if (x.error()) {
return x.error(); }
107 inline simdjson_result<std::string_view>
to_json_string(simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> x) {
108 if (x.error()) {
return x.error(); }
113 namespace simdjson {
namespace SIMDJSON_IMPLEMENTATION {
namespace ondemand {
115 #if SIMDJSON_EXCEPTIONS
127 return (out << x.
value());
136 return (out << error);
141 #if SIMDJSON_EXCEPTIONS
153 return (out << x.
value());
162 return (out << error);
167 #if SIMDJSON_EXCEPTIONS
188 return (out << x.
value());
192 return (out << x.
value());
201 return (out << error);
206 #if SIMDJSON_EXCEPTIONS
218 return (out << x.
value());
227 return (out << error);
A forward-only JSON array.
A document_reference is a thin wrapper around a document reference instance.
A forward-only JSON object field iterator.
An ephemeral JSON value returned during iteration.
std::ostream & operator<<(std::ostream &out, json_type type) noexcept
Write the JSON type to the output stream.
json_type
The type of a JSON value.
@ object
A JSON object ( { "a": 1, "b" 2, ... } )
@ array
A JSON array ( [ 1, 2, 3 ... ] )
The top level simdjson namespace, containing everything the library provides.
simdjson_result< std::string_view > to_json_string(SIMDJSON_IMPLEMENTATION::ondemand::document &x) noexcept
Create a string-view instance out of a document instance.
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.