| 1 | #include "simdjson/dom/serialization.h" |
| 2 | #include "simdjson/error.h" |
| 3 | |
| 4 | namespace simdjson { |
| 5 | /** |
| 6 | * Create a string-view instance out of a document instance. The string-view instance |
| 7 | * contains JSON text that is suitable to be parsed as JSON again. It does not |
| 8 | * validate the content. |
| 9 | */ |
| 10 | inline simdjson_result<std::string_view> to_json_string(SIMDJSON_IMPLEMENTATION::ondemand::document& x) noexcept; |
| 11 | /** |
| 12 | * Create a string-view instance out of a value instance. The string-view instance |
| 13 | * contains JSON text that is suitable to be parsed as JSON again. The value must |
| 14 | * not have been accessed previously. It does not |
| 15 | * validate the content. |
| 16 | */ |
| 17 | inline simdjson_result<std::string_view> to_json_string(SIMDJSON_IMPLEMENTATION::ondemand::value& x) noexcept; |
| 18 | /** |
| 19 | * Create a string-view instance out of an object instance. The string-view instance |
| 20 | * contains JSON text that is suitable to be parsed as JSON again. It does not |
| 21 | * validate the content. |
| 22 | */ |
| 23 | inline simdjson_result<std::string_view> to_json_string(SIMDJSON_IMPLEMENTATION::ondemand::object& x) noexcept; |
| 24 | /** |
| 25 | * Create a string-view instance out of an array instance. The string-view instance |
| 26 | * contains JSON text that is suitable to be parsed as JSON again. It does not |
| 27 | * validate the content. |
| 28 | */ |
| 29 | inline simdjson_result<std::string_view> to_json_string(SIMDJSON_IMPLEMENTATION::ondemand::array& x) noexcept; |
| 30 | inline simdjson_result<std::string_view> to_json_string(simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document> x); |
| 31 | inline simdjson_result<std::string_view> to_json_string(simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> x); |
| 32 | inline simdjson_result<std::string_view> to_json_string(simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> x); |
| 33 | inline simdjson_result<std::string_view> to_json_string(simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> x); |
| 34 | } // namespace simdjson |
| 35 | |
| 36 | /** |
| 37 | * We want to support argument-dependent lookup (ADL). |
| 38 | * Hence we should define operator<< in the namespace |
| 39 | * where the argument (here value, object, etc.) resides. |
| 40 | * Credit: @madhur4127 |
| 41 | * See https://github.com/simdjson/simdjson/issues/1768 |
| 42 | */ |
| 43 | namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { namespace ondemand { |
| 44 | |
| 45 | /** |
| 46 | * Print JSON to an output stream. It does not |
| 47 | * validate the content. |
| 48 | * |
| 49 | * @param out The output stream. |
| 50 | * @param value The element. |
| 51 | * @throw if there is an error with the underlying output stream. simdjson itself will not throw. |
| 52 | */ |
| 53 | inline std::ostream& operator<<(std::ostream& out, simdjson::SIMDJSON_IMPLEMENTATION::ondemand::value x); |
| 54 | #if SIMDJSON_EXCEPTIONS |
| 55 | inline std::ostream& operator<<(std::ostream& out, simdjson::simdjson_result<simdjson::SIMDJSON_IMPLEMENTATION::ondemand::value> x); |
| 56 | #endif |
| 57 | /** |
| 58 | * Print JSON to an output stream. It does not |
| 59 | * validate the content. |
| 60 | * |
| 61 | * @param out The output stream. |
| 62 | * @param value The array. |
| 63 | * @throw if there is an error with the underlying output stream. simdjson itself will not throw. |
| 64 | */ |
| 65 | inline std::ostream& operator<<(std::ostream& out, simdjson::SIMDJSON_IMPLEMENTATION::ondemand::array value); |
| 66 | #if SIMDJSON_EXCEPTIONS |
| 67 | inline std::ostream& operator<<(std::ostream& out, simdjson::simdjson_result<simdjson::SIMDJSON_IMPLEMENTATION::ondemand::array> x); |
| 68 | #endif |
| 69 | /** |
| 70 | * Print JSON to an output stream. It does not |
| 71 | * validate the content. |
| 72 | * |
| 73 | * @param out The output stream. |
| 74 | * @param value The array. |
| 75 | * @throw if there is an error with the underlying output stream. simdjson itself will not throw. |
| 76 | */ |
| 77 | inline std::ostream& operator<<(std::ostream& out, simdjson::SIMDJSON_IMPLEMENTATION::ondemand::document& value); |
| 78 | #if SIMDJSON_EXCEPTIONS |
| 79 | inline std::ostream& operator<<(std::ostream& out, simdjson::simdjson_result<simdjson::SIMDJSON_IMPLEMENTATION::ondemand::document>&& x); |
| 80 | #endif |
| 81 | inline std::ostream& operator<<(std::ostream& out, simdjson::SIMDJSON_IMPLEMENTATION::ondemand::document_reference& value); |
| 82 | #if SIMDJSON_EXCEPTIONS |
| 83 | inline std::ostream& operator<<(std::ostream& out, simdjson::simdjson_result<simdjson::SIMDJSON_IMPLEMENTATION::ondemand::document_reference>&& x); |
| 84 | #endif |
| 85 | /** |
| 86 | * Print JSON to an output stream. It does not |
| 87 | * validate the content. |
| 88 | * |
| 89 | * @param out The output stream. |
| 90 | * @param value The object. |
| 91 | * @throw if there is an error with the underlying output stream. simdjson itself will not throw. |
| 92 | */ |
| 93 | inline std::ostream& operator<<(std::ostream& out, simdjson::SIMDJSON_IMPLEMENTATION::ondemand::object value); |
| 94 | #if SIMDJSON_EXCEPTIONS |
| 95 | inline std::ostream& operator<<(std::ostream& out, simdjson::simdjson_result<simdjson::SIMDJSON_IMPLEMENTATION::ondemand::object> x); |
| 96 | #endif |
| 97 | }}} // namespace simdjson::SIMDJSON_IMPLEMENTATION::ondemand |