mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7382dc2be8 | |||
| 8c14e0c56f | |||
| a9a62feb75 | |||
| b9228b4d3c | |||
| 726c3eb611 | |||
| 4cdc4f18ef |
+1
-1
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14)
|
|||||||
project(
|
project(
|
||||||
simdjson
|
simdjson
|
||||||
# The version number is modified by tools/release.py
|
# The version number is modified by tools/release.py
|
||||||
VERSION 3.12.2
|
VERSION 3.12.3
|
||||||
DESCRIPTION "Parsing gigabytes of JSON per second"
|
DESCRIPTION "Parsing gigabytes of JSON per second"
|
||||||
HOMEPAGE_URL "https://simdjson.org/"
|
HOMEPAGE_URL "https://simdjson.org/"
|
||||||
LANGUAGES CXX C
|
LANGUAGES CXX C
|
||||||
|
|||||||
+1
-1
@@ -92,7 +92,7 @@ We welcome contributions from women and less represented groups. If you need hel
|
|||||||
|
|
||||||
Consider the following points when engaging with the project:
|
Consider the following points when engaging with the project:
|
||||||
|
|
||||||
- We discourage arguments from authority: ideas are discusssed on their own merits and not based on who stated it.
|
- We discourage arguments from authority: ideas are discussed on their own merits and not based on who stated it.
|
||||||
- Be mindful that what you may view as an aggression is maybe merely a difference of opinion or a misunderstanding.
|
- Be mindful that what you may view as an aggression is maybe merely a difference of opinion or a misunderstanding.
|
||||||
- Be mindful that a collection of small aggressions, even if mild in isolation, can become harmful.
|
- Be mindful that a collection of small aggressions, even if mild in isolation, can become harmful.
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ PROJECT_NAME = simdjson
|
|||||||
# could be handy for archiving the generated documentation or if some version
|
# could be handy for archiving the generated documentation or if some version
|
||||||
# control system is used.
|
# control system is used.
|
||||||
|
|
||||||
PROJECT_NUMBER = "3.12.2"
|
PROJECT_NUMBER = "3.12.3"
|
||||||
|
|
||||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||||
# for a project that appears at the top of each page and should give viewer a
|
# for a project that appears at the top of each page and should give viewer a
|
||||||
|
|||||||
@@ -173,7 +173,8 @@ We distinguish between "bindings" (which just wrap the C++ code) and a port to a
|
|||||||
- [simdjsone](https://github.com/saleyn/simdjsone): erlang bindings.
|
- [simdjsone](https://github.com/saleyn/simdjsone): erlang bindings.
|
||||||
- [lua-simdjson](https://github.com/FourierTransformer/lua-simdjson): lua bindings.
|
- [lua-simdjson](https://github.com/FourierTransformer/lua-simdjson): lua bindings.
|
||||||
- [hermes-json](https://hackage.haskell.org/package/hermes-json): haskell bindings.
|
- [hermes-json](https://hackage.haskell.org/package/hermes-json): haskell bindings.
|
||||||
- [simdjzon](https://github.com/travisstaloch/simdjzon): zig port.
|
- [zimdjson](https://github.com/EzequielRamis/zimdjson): Zig port.
|
||||||
|
- [simdjzon](https://github.com/travisstaloch/simdjzon): Zig port.
|
||||||
- [JSON-Simd](https://github.com/rawleyfowler/JSON-simd): Raku bindings.
|
- [JSON-Simd](https://github.com/rawleyfowler/JSON-simd): Raku bindings.
|
||||||
- [JSON::SIMD](https://metacpan.org/pod/JSON::SIMD): Perl bindings; fully-featured JSON module that uses simdjson for decoding.
|
- [JSON::SIMD](https://metacpan.org/pod/JSON::SIMD): Perl bindings; fully-featured JSON module that uses simdjson for decoding.
|
||||||
- [gemmaJSON](https://github.com/sainttttt/gemmaJSON): Nim JSON parser based on simdjson bindings.
|
- [gemmaJSON](https://github.com/sainttttt/gemmaJSON): Nim JSON parser based on simdjson bindings.
|
||||||
|
|||||||
+49
-3
@@ -1243,7 +1243,6 @@ int main() {
|
|||||||
You may also conditionally fill in `std::optional` values.
|
You may also conditionally fill in `std::optional` values.
|
||||||
|
|
||||||
```C++
|
```C++
|
||||||
|
|
||||||
padded_string json =
|
padded_string json =
|
||||||
R"( { "car1": { "make": "Toyota", "model": "Camry", "year": 2018,
|
R"( { "car1": { "make": "Toyota", "model": "Camry", "year": 2018,
|
||||||
"tire_pressure": [ 40.1, 39.9 ] }
|
"tire_pressure": [ 40.1, 39.9 ] }
|
||||||
@@ -1258,6 +1257,23 @@ You may also conditionally fill in `std::optional` values.
|
|||||||
// error is simdjson::SUCCESS
|
// error is simdjson::SUCCESS
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also deserialized to map-like types with keys that can be constructed
|
||||||
|
from `std::string_view` instances:
|
||||||
|
|
||||||
|
|
||||||
|
```C++
|
||||||
|
padded_string json =
|
||||||
|
R"( { "car1": { "make": "Toyota", "model": "Camry", "year": 2018,
|
||||||
|
"tire_pressure": [ 40.1, 39.9 ] }
|
||||||
|
})"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document doc = parser.iterate(json);
|
||||||
|
std:map<std::string,Car> cars;
|
||||||
|
error = doc.get<std:map<std::string,Car>>().get(cars);
|
||||||
|
// car has value car1->Car{"Toyota", "Camry", 2018, {40.1f, 39.9f}}
|
||||||
|
// error is simdjson::SUCCESS
|
||||||
|
```
|
||||||
|
|
||||||
And so forth.
|
And so forth.
|
||||||
|
|
||||||
Advanced users may want to overwrite the defaults provided by the simdjson library.
|
Advanced users may want to overwrite the defaults provided by the simdjson library.
|
||||||
@@ -1531,7 +1547,20 @@ Some errors are recoverable:
|
|||||||
* You may get the error `simdjson::INCORRECT_TYPE` after trying to convert a value to an incorrect type: e.g., you expected a number and try to convert the value to a number, but it is an array.
|
* You may get the error `simdjson::INCORRECT_TYPE` after trying to convert a value to an incorrect type: e.g., you expected a number and try to convert the value to a number, but it is an array.
|
||||||
* You may query a key from an object, but the key is missing in which case you get the error `simdjson::NO_SUCH_FIELD`: e.g., you call `obj["myname"]` and the object does not have a key `"myname"`.
|
* You may query a key from an object, but the key is missing in which case you get the error `simdjson::NO_SUCH_FIELD`: e.g., you call `obj["myname"]` and the object does not have a key `"myname"`.
|
||||||
|
|
||||||
Other errors (e.g., `simdjson::INCOMPLETE_ARRAY_OR_OBJECT`) may indicate a fatal error and often follow from the fact that the document is not valid JSON. In which case, it is no longer possible to continue accessing the document: calling the method `is_alive()` on the document instance returns false. All following accesses will keep returning the same fatal error (e.g., `simdjson::INCOMPLETE_ARRAY_OR_OBJECT`).
|
Other errors (`simdjson::INCOMPLETE_ARRAY_OR_OBJECT` and `simdjson::TAPE_ERROR`) indicate a fatal error and follow from the fact that the document is not valid JSON. These errors are not recoverable: you cannot continue. In which case, it is no longer safe to continue accessing the document: calling the method `is_alive()` on the document instance returns false. It is your responsibility as a user to stop using the simdjson
|
||||||
|
document after encountering these fatal errors. Consider the following example, after
|
||||||
|
the fatal error, the document instance cannot be used. Observe how the JSON input is invalid.
|
||||||
|
```cpp
|
||||||
|
simdjson::padded_string badjson = R"( { "make": "Toyota", "model": "Camry", "year"})"_padded;
|
||||||
|
simdjson::ondemand::parser parser;
|
||||||
|
simdjson::ondemand::document doc;
|
||||||
|
auto errordoc = parser.iterate(badjson).get(doc);
|
||||||
|
// errordoc == simdjson::SUCCESS
|
||||||
|
simdjson::ondemand::value v;
|
||||||
|
auto error = doc.get_object()["year"].get(v);
|
||||||
|
// simdjson::is_fatal(error)) is true!
|
||||||
|
// doc.is_alive() is false
|
||||||
|
```
|
||||||
|
|
||||||
When you use the code without exceptions, it is your responsibility to check for error before using the
|
When you use the code without exceptions, it is your responsibility to check for error before using the
|
||||||
result: if there is an error, the result value will not be valid and using it will caused undefined behavior. Most compilers should be able to help you if you activate the right
|
result: if there is an error, the result value will not be valid and using it will caused undefined behavior. Most compilers should be able to help you if you activate the right
|
||||||
@@ -1920,6 +1949,8 @@ conclude that you have trailing content and that your document is not valid JSON
|
|||||||
You may then use `doc.current_location()` to obtain a pointer to the start of the trailing
|
You may then use `doc.current_location()` to obtain a pointer to the start of the trailing
|
||||||
content.
|
content.
|
||||||
|
|
||||||
|
Example 1.
|
||||||
|
|
||||||
```C++
|
```C++
|
||||||
auto json = R"([1, 2] foo ])"_padded;
|
auto json = R"([1, 2] foo ])"_padded;
|
||||||
ondemand::parser parser;
|
ondemand::parser parser;
|
||||||
@@ -1934,6 +1965,21 @@ content.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example 2.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto json = R"(["extra close"]])"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document doc = parser.iterate(json);
|
||||||
|
ondemand::array array = doc.get_array();
|
||||||
|
for (std::string_view values : array) {
|
||||||
|
std::cout << values << std::endl;
|
||||||
|
}
|
||||||
|
if(!doc.at_end()) {
|
||||||
|
std::cerr << "trailing content at byte index " << doc.current_location() - json.data() << std::endl;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
The `at_end()` method is equivalent to `doc.current_location().error() == simdjson::SUCCESS` but
|
The `at_end()` method is equivalent to `doc.current_location().error() == simdjson::SUCCESS` but
|
||||||
more convenient.
|
more convenient.
|
||||||
|
|
||||||
@@ -2545,7 +2591,7 @@ The CPU detection, which runs the first time parsing is attempted and switches t
|
|||||||
parser for your CPU, is transparent and thread-safe.
|
parser for your CPU, is transparent and thread-safe.
|
||||||
Our runtime dispatching is based on global objects that are instantiated at the beginning of the
|
Our runtime dispatching is based on global objects that are instantiated at the beginning of the
|
||||||
main thread and may be discarded at the end of the main thread. If you have multiple threads running
|
main thread and may be discarded at the end of the main thread. If you have multiple threads running
|
||||||
and some threads use the library while the main thread is cleaning up ressources, you may encounter
|
and some threads use the library while the main thread is cleaning up resources, you may encounter
|
||||||
issues. If you expect such problems, you may consider using [std::quick_exit](https://en.cppreference.com/w/cpp/utility/program/quick_exit).
|
issues. If you expect such problems, you may consider using [std::quick_exit](https://en.cppreference.com/w/cpp/utility/program/quick_exit).
|
||||||
|
|
||||||
In a threaded environment, stack space is often limited. Running code like simdjson in debug mode may require hundreds of kilobytes of stack memory. Thus stack overflows are a possibility. We recommend you turn on optimization when working in an environment where stack space is limited. If you must run your code in debug mode, we recommend you configure your system to have more stack space. We discourage you from running production code based on a debug build.
|
In a threaded environment, stack space is often limited. Running code like simdjson in debug mode may require hundreds of kilobytes of stack memory. Thus stack overflows are a possibility. We recommend you turn on optimization when working in an environment where stack space is limited. If you must run your code in debug mode, we recommend you configure your system to have more stack space. We discourage you from running production code based on a debug build.
|
||||||
|
|||||||
+1
-1
@@ -733,5 +733,5 @@ Setting the `realloc_if_needed` parameter `false` in this manner may lead to bet
|
|||||||
Performance Tips
|
Performance Tips
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
- For release builds, we recommend setting `NDEBUG` pre-processor directive when compiling the `simdjson` library. Importantly, using the optimization flags `-O2` or `-O3` under GCC and LLVM clang does not set the `NDEBUG` directrive, you must set it manually (e.g., `-DNDEBUG`).
|
- For release builds, we recommend setting `NDEBUG` pre-processor directive when compiling the `simdjson` library. Importantly, using the optimization flags `-O2` or `-O3` under GCC and LLVM clang does not set the `NDEBUG` directive, you must set it manually (e.g., `-DNDEBUG`).
|
||||||
- For long streams of JSON documents, consider [`iterate_many`](iterate_many.md) and [`parse_many`](parse_many.md) for better performance.
|
- For long streams of JSON documents, consider [`iterate_many`](iterate_many.md) and [`parse_many`](parse_many.md) for better performance.
|
||||||
|
|||||||
+1
-1
@@ -367,7 +367,7 @@ Please see our main documentation (`basics.md`) under
|
|||||||
"Use `tag_invoke` for custom types (C++20)" for details about
|
"Use `tag_invoke` for custom types (C++20)" for details about
|
||||||
tag_invoke functions.
|
tag_invoke functions.
|
||||||
|
|
||||||
Given a stream of JSON documents, you can add them to a data struture
|
Given a stream of JSON documents, you can add them to a data structure
|
||||||
such as a `std::vector<Car>` like so if you support exceptions:
|
such as a `std::vector<Car>` like so if you support exceptions:
|
||||||
|
|
||||||
```C++
|
```C++
|
||||||
|
|||||||
@@ -32,14 +32,30 @@ SIMDJSON_IMPL_CONCEPT(op_append, operator+=)
|
|||||||
#undef SIMDJSON_IMPL_CONCEPT
|
#undef SIMDJSON_IMPL_CONCEPT
|
||||||
} // namespace details
|
} // namespace details
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
concept string_view_like = std::is_convertible_v<T, std::string_view> &&
|
||||||
|
!std::is_convertible_v<T, const char*>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept constructible_from_string_view = std::is_constructible_v<T, std::string_view>
|
||||||
|
&& !std::is_same_v<T, std::string_view>
|
||||||
|
&& std::is_default_constructible_v<T>;
|
||||||
|
|
||||||
|
template<typename M>
|
||||||
|
concept string_view_keyed_map = string_view_like<typename M::key_type>
|
||||||
|
&& requires(std::remove_cvref_t<M>& m, typename M::key_type sv, typename M::mapped_type v) {
|
||||||
|
{ m.emplace(sv, v) } -> std::same_as<std::pair<typename M::iterator, bool>>;
|
||||||
|
};
|
||||||
|
|
||||||
/// Check if T is a container that we can append to, including:
|
/// Check if T is a container that we can append to, including:
|
||||||
/// std::vector, std::deque, std::list, std::string, ...
|
/// std::vector, std::deque, std::list, std::string, ...
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept appendable_containers =
|
concept appendable_containers =
|
||||||
details::supports_emplace_back<T> || details::supports_emplace<T> ||
|
(details::supports_emplace_back<T> || details::supports_emplace<T> ||
|
||||||
details::supports_push_back<T> || details::supports_push<T> ||
|
details::supports_push_back<T> || details::supports_push<T> ||
|
||||||
details::supports_add<T> || details::supports_append<T> ||
|
details::supports_add<T> || details::supports_append<T> ||
|
||||||
details::supports_insert<T>;
|
details::supports_insert<T>) && !string_view_keyed_map<T>;
|
||||||
|
|
||||||
/// Insert into the container however possible
|
/// Insert into the container however possible
|
||||||
template <appendable_containers T, typename... Args>
|
template <appendable_containers T, typename... Args>
|
||||||
@@ -107,6 +123,8 @@ concept optional_type = requires(std::remove_cvref_t<T> obj) {
|
|||||||
{ static_cast<bool>(obj) } -> std::same_as<bool>; // convertible to bool
|
{ static_cast<bool>(obj) } -> std::same_as<bool>; // convertible to bool
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace concepts
|
} // namespace concepts
|
||||||
} // namespace simdjson
|
} // namespace simdjson
|
||||||
#endif // SIMDJSON_SUPPORTS_DESERIALIZATION
|
#endif // SIMDJSON_SUPPORTS_DESERIALIZATION
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public:
|
|||||||
* The memory allocation is strict: you
|
* The memory allocation is strict: you
|
||||||
* can you use this function to increase
|
* can you use this function to increase
|
||||||
* or lower the amount of allocated memory.
|
* or lower the amount of allocated memory.
|
||||||
* Passsing zero clears the memory.
|
* Passing zero clears the memory.
|
||||||
*/
|
*/
|
||||||
error_code allocate(size_t len) noexcept;
|
error_code allocate(size_t len) noexcept;
|
||||||
/** @private Capacity in bytes, in terms
|
/** @private Capacity in bytes, in terms
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ public:
|
|||||||
* arrays or objects) MUST be separated with whitespace.
|
* arrays or objects) MUST be separated with whitespace.
|
||||||
*
|
*
|
||||||
* The documents must not exceed batch_size bytes (by default 1MB) or they will fail to parse.
|
* The documents must not exceed batch_size bytes (by default 1MB) or they will fail to parse.
|
||||||
* Setting batch_size to excessively large or excesively small values may impact negatively the
|
* Setting batch_size to excessively large or excessively small values may impact negatively the
|
||||||
* performance.
|
* performance.
|
||||||
*
|
*
|
||||||
* ### Error Handling
|
* ### Error Handling
|
||||||
@@ -434,7 +434,7 @@ public:
|
|||||||
* arrays or objects) MUST be separated with whitespace.
|
* arrays or objects) MUST be separated with whitespace.
|
||||||
*
|
*
|
||||||
* The documents must not exceed batch_size bytes (by default 1MB) or they will fail to parse.
|
* The documents must not exceed batch_size bytes (by default 1MB) or they will fail to parse.
|
||||||
* Setting batch_size to excessively large or excesively small values may impact negatively the
|
* Setting batch_size to excessively large or excessively small values may impact negatively the
|
||||||
* performance.
|
* performance.
|
||||||
*
|
*
|
||||||
* ### Error Handling
|
* ### Error Handling
|
||||||
|
|||||||
@@ -6,6 +6,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace simdjson {
|
namespace simdjson {
|
||||||
|
|
||||||
|
inline bool is_fatal(error_code error) noexcept {
|
||||||
|
return error == TAPE_ERROR || error == INCOMPLETE_ARRAY_OR_OBJECT;
|
||||||
|
}
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
// We store the error code so we can validate the error message is associated with the right code
|
// We store the error code so we can validate the error message is associated with the right code
|
||||||
struct error_code_info {
|
struct error_code_info {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ enum error_code {
|
|||||||
SUCCESS = 0, ///< No error
|
SUCCESS = 0, ///< No error
|
||||||
CAPACITY, ///< This parser can't support a document that big
|
CAPACITY, ///< This parser can't support a document that big
|
||||||
MEMALLOC, ///< Error allocating memory, most likely out of memory
|
MEMALLOC, ///< Error allocating memory, most likely out of memory
|
||||||
TAPE_ERROR, ///< Something went wrong, this is a generic error
|
TAPE_ERROR, ///< Something went wrong, this is a generic error. Fatal/unrecoverable error.
|
||||||
DEPTH_ERROR, ///< Your document exceeds the user-specified depth limitation
|
DEPTH_ERROR, ///< Your document exceeds the user-specified depth limitation
|
||||||
STRING_ERROR, ///< Problem while parsing a string
|
STRING_ERROR, ///< Problem while parsing a string
|
||||||
T_ATOM_ERROR, ///< Problem while parsing an atom starting with the letter 't'
|
T_ATOM_ERROR, ///< Problem while parsing an atom starting with the letter 't'
|
||||||
@@ -45,13 +45,21 @@ enum error_code {
|
|||||||
PARSER_IN_USE, ///< parser is already in use.
|
PARSER_IN_USE, ///< parser is already in use.
|
||||||
OUT_OF_ORDER_ITERATION, ///< tried to iterate an array or object out of order (checked when SIMDJSON_DEVELOPMENT_CHECKS=1)
|
OUT_OF_ORDER_ITERATION, ///< tried to iterate an array or object out of order (checked when SIMDJSON_DEVELOPMENT_CHECKS=1)
|
||||||
INSUFFICIENT_PADDING, ///< The JSON doesn't have enough padding for simdjson to safely parse it.
|
INSUFFICIENT_PADDING, ///< The JSON doesn't have enough padding for simdjson to safely parse it.
|
||||||
INCOMPLETE_ARRAY_OR_OBJECT, ///< The document ends early.
|
INCOMPLETE_ARRAY_OR_OBJECT, ///< The document ends early. Fatal/unrecoverable error.
|
||||||
SCALAR_DOCUMENT_AS_VALUE, ///< A scalar document is treated as a value.
|
SCALAR_DOCUMENT_AS_VALUE, ///< A scalar document is treated as a value.
|
||||||
OUT_OF_BOUNDS, ///< Attempted to access location outside of document.
|
OUT_OF_BOUNDS, ///< Attempted to access location outside of document.
|
||||||
TRAILING_CONTENT, ///< Unexpected trailing content in the JSON input
|
TRAILING_CONTENT, ///< Unexpected trailing content in the JSON input
|
||||||
NUM_ERROR_CODES
|
NUM_ERROR_CODES
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some errors are fatal and invalidate the document. This function returns true if the
|
||||||
|
* error is fatal. It returns true for TAPE_ERROR and INCOMPLETE_ARRAY_OR_OBJECT.
|
||||||
|
* Once a fatal error is encountered, the on-demand document is no longer valid and
|
||||||
|
* processing should stop.
|
||||||
|
*/
|
||||||
|
inline bool is_fatal(error_code error) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It is the convention throughout the code that the macro SIMDJSON_DEVELOPMENT_CHECKS determines whether
|
* It is the convention throughout the code that the macro SIMDJSON_DEVELOPMENT_CHECKS determines whether
|
||||||
* we check for OUT_OF_ORDER_ITERATION. The logic behind it is that these errors only occurs when the code
|
* we check for OUT_OF_ORDER_ITERATION. The logic behind it is that these errors only occurs when the code
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ simdjson_inline bool compute_float_64(int64_t power, uint64_t i, bool negative,
|
|||||||
// floor(log(5**power)/log(2))
|
// floor(log(5**power)/log(2))
|
||||||
//
|
//
|
||||||
// Note that this is not magic: 152170/(1<<16) is
|
// Note that this is not magic: 152170/(1<<16) is
|
||||||
// approximatively equal to log(5)/log(2).
|
// approximately equal to log(5)/log(2).
|
||||||
// The 1<<16 value is a power of two; we could use a
|
// The 1<<16 value is a power of two; we could use a
|
||||||
// larger power of 2 if we wanted to.
|
// larger power of 2 if we wanted to.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -239,20 +239,27 @@ public:
|
|||||||
if constexpr (custom_deserializable<T, document>) {
|
if constexpr (custom_deserializable<T, document>) {
|
||||||
return deserialize(*this, out);
|
return deserialize(*this, out);
|
||||||
} else {
|
} else {
|
||||||
#endif // SIMDJSON_SUPPORTS_DESERIALIZATION
|
static_assert(!sizeof(T), "The get<T> method with type T is not implemented by the simdjson library. "
|
||||||
// Unless the simdjson library or the user provides an inline implementation, calling this method should
|
"And you do not seem to have added support for it. Indeed, we have that "
|
||||||
// immediately fail.
|
"simdjson::custom_deserializable<T> is false and the type T is not a default type "
|
||||||
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
|
"such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
||||||
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
"int64_t, double, or bool.");
|
||||||
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
|
|
||||||
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
|
|
||||||
" You may also add support for custom types, see our documentation.");
|
|
||||||
static_cast<void>(out); // to get rid of unused errors
|
static_cast<void>(out); // to get rid of unused errors
|
||||||
return UNINITIALIZED;
|
return UNINITIALIZED;
|
||||||
#if SIMDJSON_SUPPORTS_DESERIALIZATION
|
|
||||||
}
|
}
|
||||||
#endif
|
#else // SIMDJSON_SUPPORTS_DESERIALIZATION
|
||||||
|
// Unless the simdjson library or the user provides an inline implementation, calling this method should
|
||||||
|
// immediately fail.
|
||||||
|
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
|
||||||
|
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
||||||
|
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
|
||||||
|
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
|
||||||
|
" You may also add support for custom types, see our documentation.");
|
||||||
|
static_cast<void>(out); // to get rid of unused errors
|
||||||
|
return UNINITIALIZED;
|
||||||
|
#endif // SIMDJSON_SUPPORTS_DESERIALIZATION
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @overload template<typename T> error_code get(T &out) & noexcept */
|
/** @overload template<typename T> error_code get(T &out) & noexcept */
|
||||||
template<typename T> simdjson_deprecated simdjson_inline error_code get(T &out) && noexcept;
|
template<typename T> simdjson_deprecated simdjson_inline error_code get(T &out) && noexcept;
|
||||||
|
|
||||||
@@ -814,20 +821,27 @@ public:
|
|||||||
if constexpr (custom_deserializable<T, document_reference>) {
|
if constexpr (custom_deserializable<T, document_reference>) {
|
||||||
return deserialize(*this, out);
|
return deserialize(*this, out);
|
||||||
} else {
|
} else {
|
||||||
#endif // SIMDJSON_SUPPORTS_DESERIALIZATION
|
static_assert(!sizeof(T), "The get<T> method with type T is not implemented by the simdjson library. "
|
||||||
// Unless the simdjson library or the user provides an inline implementation, calling this method should
|
"And you do not seem to have added support for it. Indeed, we have that "
|
||||||
// immediately fail.
|
"simdjson::custom_deserializable<T> is false and the type T is not a default type "
|
||||||
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
|
"such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
||||||
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
"int64_t, double, or bool.");
|
||||||
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
|
|
||||||
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
|
|
||||||
" You may also add support for custom types, see our documentation.");
|
|
||||||
static_cast<void>(out); // to get rid of unused errors
|
static_cast<void>(out); // to get rid of unused errors
|
||||||
return UNINITIALIZED;
|
return UNINITIALIZED;
|
||||||
#if SIMDJSON_SUPPORTS_DESERIALIZATION
|
|
||||||
}
|
}
|
||||||
#endif
|
#else // SIMDJSON_SUPPORTS_DESERIALIZATION
|
||||||
|
// Unless the simdjson library or the user provides an inline implementation, calling this method should
|
||||||
|
// immediately fail.
|
||||||
|
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
|
||||||
|
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
||||||
|
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
|
||||||
|
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
|
||||||
|
" You may also add support for custom types, see our documentation.");
|
||||||
|
static_cast<void>(out); // to get rid of unused errors
|
||||||
|
return UNINITIALIZED;
|
||||||
|
#endif // SIMDJSON_SUPPORTS_DESERIALIZATION
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @overload template<typename T> error_code get(T &out) & noexcept */
|
/** @overload template<typename T> error_code get(T &out) & noexcept */
|
||||||
template<typename T> simdjson_inline error_code get(T &out) && noexcept;
|
template<typename T> simdjson_inline error_code get(T &out) && noexcept;
|
||||||
simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
|
simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
|
||||||
|
|||||||
@@ -55,6 +55,16 @@ error_code tag_invoke(deserialize_tag, auto &val, T &out) noexcept {
|
|||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <concepts::constructible_from_string_view T, typename ValT>
|
||||||
|
requires(!require_custom_serialization<T>)
|
||||||
|
error_code tag_invoke(deserialize_tag, ValT &val, T &out) noexcept(std::is_nothrow_constructible_v<T, std::string_view>) {
|
||||||
|
std::string_view str;
|
||||||
|
SIMDJSON_TRY(val.get_string().get(str));
|
||||||
|
out = T{str};
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STL containers have several constructors including one that takes a single
|
* STL containers have several constructors including one that takes a single
|
||||||
* size argument. Thus, some compilers (Visual Studio) will not be able to
|
* size argument. Thus, some compilers (Visual Studio) will not be able to
|
||||||
@@ -100,6 +110,39 @@ error_code tag_invoke(deserialize_tag, ValT &val, T &out) noexcept(false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We want to support std::map and std::unordered_map but only for
|
||||||
|
* string-keyed types.
|
||||||
|
*/
|
||||||
|
template <concepts::string_view_keyed_map T, typename ValT>
|
||||||
|
requires(!require_custom_serialization<T>)
|
||||||
|
error_code tag_invoke(deserialize_tag, ValT &val, T &out) noexcept(false) {
|
||||||
|
using value_type = typename std::remove_cvref_t<T>::mapped_type;
|
||||||
|
static_assert(
|
||||||
|
deserializable<value_type, ValT>,
|
||||||
|
"The specified value type inside the container must itself be deserializable");
|
||||||
|
static_assert(
|
||||||
|
std::is_default_constructible_v<value_type>,
|
||||||
|
"The specified value type inside the container must default constructible.");
|
||||||
|
SIMDJSON_IMPLEMENTATION::ondemand::object obj;
|
||||||
|
SIMDJSON_TRY(val.get_object().get(obj));
|
||||||
|
for (auto field : obj) {
|
||||||
|
std::string_view key;
|
||||||
|
SIMDJSON_TRY(field.unescaped_key().get(key));
|
||||||
|
value_type this_value;
|
||||||
|
SIMDJSON_TRY(field.value().get<value_type>().get(this_value));
|
||||||
|
[[maybe_unused]] std::pair<typename T::iterator, bool> result = out.emplace(key, this_value);
|
||||||
|
// unclear what to do if the key already exists
|
||||||
|
// if (result.second == false) {
|
||||||
|
// // key already exists
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
(void)out;
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This CPO (Customization Point Object) will help deserialize into
|
* This CPO (Customization Point Object) will help deserialize into
|
||||||
|
|||||||
@@ -70,22 +70,28 @@ public:
|
|||||||
noexcept
|
noexcept
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if SIMDJSON_SUPPORTS_DESERIALIZATION
|
#if SIMDJSON_SUPPORTS_DESERIALIZATION
|
||||||
if constexpr (custom_deserializable<T, value>) {
|
if constexpr (custom_deserializable<T, value>) {
|
||||||
return deserialize(*this, out);
|
return deserialize(*this, out);
|
||||||
} else {
|
} else {
|
||||||
#endif // SIMDJSON_SUPPORTS_DESERIALIZATION
|
static_assert(!sizeof(T), "The get<T> method with type T is not implemented by the simdjson library. "
|
||||||
// Unless the simdjson library or the user provides an inline implementation, calling this method should
|
"And you do not seem to have added support for it. Indeed, we have that "
|
||||||
// immediately fail.
|
"simdjson::custom_deserializable<T> is false and the type T is not a default type "
|
||||||
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
|
"such as ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
||||||
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
"int64_t, double, or bool.");
|
||||||
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
|
static_cast<void>(out); // to get rid of unused errors
|
||||||
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
|
return UNINITIALIZED;
|
||||||
" You may also add support for custom types, see our documentation.");
|
}
|
||||||
static_cast<void>(out); // to get rid of unused errors
|
#else // SIMDJSON_SUPPORTS_DESERIALIZATION
|
||||||
return UNINITIALIZED;
|
// Unless the simdjson library or the user provides an inline implementation, calling this method should
|
||||||
#if SIMDJSON_SUPPORTS_DESERIALIZATION
|
// immediately fail.
|
||||||
}
|
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
|
||||||
|
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
||||||
|
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
|
||||||
|
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template."
|
||||||
|
" You may also add support for custom types, see our documentation.");
|
||||||
|
static_cast<void>(out); // to get rid of unused errors
|
||||||
|
return UNINITIALIZED;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -778,19 +778,23 @@ simdjson_warn_unused simdjson_inline simdjson_result<double> value_iterator::get
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<bool> value_iterator::get_root_bool(bool check_trailing) noexcept {
|
simdjson_warn_unused simdjson_inline simdjson_result<bool> value_iterator::get_root_bool(bool check_trailing) noexcept {
|
||||||
auto max_len = peek_root_length();
|
auto max_len = peek_root_length();
|
||||||
auto json = peek_root_scalar("bool");
|
auto json = peek_root_scalar("bool");
|
||||||
uint8_t tmpbuf[5+1+1]; // +1 for null termination
|
// We have a boolean if we have either "true" or "false" and the next character is either
|
||||||
tmpbuf[5+1] = '\0'; // make sure that buffer is always null terminated.
|
// a structural character or whitespace. We also check that the length is correct:
|
||||||
if (!_json_iter->copy_to_buffer(json, max_len, tmpbuf, 5+1)) { return incorrect_type_error("Not a boolean"); }
|
// "true" and "false" are 4 and 5 characters long, respectively.
|
||||||
auto result = parse_bool(tmpbuf);
|
bool value_true = (max_len >= 4 && !atomparsing::str4ncmp(json, "true") &&
|
||||||
if(result.error() == SUCCESS) {
|
(max_len == 4 || jsoncharutils::is_structural_or_whitespace(json[4])));
|
||||||
if (check_trailing && !_json_iter->is_single_token()) { return TRAILING_CONTENT; }
|
bool value_false = (max_len >= 5 && !atomparsing::str4ncmp(json, "false") &&
|
||||||
advance_root_scalar("bool");
|
(max_len == 5 || jsoncharutils::is_structural_or_whitespace(json[5])));
|
||||||
}
|
if(value_true == false && value_false == false) { return incorrect_type_error("Not a boolean"); }
|
||||||
return result;
|
if (check_trailing && !_json_iter->is_single_token()) { return TRAILING_CONTENT; }
|
||||||
|
advance_root_scalar("bool");
|
||||||
|
return value_true;
|
||||||
}
|
}
|
||||||
|
|
||||||
simdjson_inline simdjson_result<bool> value_iterator::is_root_null(bool check_trailing) noexcept {
|
simdjson_inline simdjson_result<bool> value_iterator::is_root_null(bool check_trailing) noexcept {
|
||||||
auto max_len = peek_root_length();
|
auto max_len = peek_root_length();
|
||||||
auto json = peek_root_scalar("null");
|
auto json = peek_root_scalar("null");
|
||||||
|
|||||||
@@ -125,7 +125,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @returns Whether the object had any fields (returns false for empty).
|
* @returns Whether the object had any fields (returns false for empty).
|
||||||
* @error INCOMPLETE_ARRAY_OR_OBJECT If there are no more tokens (implying the *parent*
|
* @error INCOMPLETE_ARRAY_OR_OBJECT If there are no more tokens (implying the *parent*
|
||||||
* array or object is incomplete).
|
* array or object is incomplete). An INCOMPLETE_ARRAY_OR_OBJECT is an unrecoverable error that
|
||||||
|
* invalidates the document.
|
||||||
*/
|
*/
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<bool> started_object() noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<bool> started_object() noexcept;
|
||||||
/**
|
/**
|
||||||
@@ -135,7 +136,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @returns Whether the object had any fields (returns false for empty).
|
* @returns Whether the object had any fields (returns false for empty).
|
||||||
* @error INCOMPLETE_ARRAY_OR_OBJECT If there are no more tokens (implying the *parent*
|
* @error INCOMPLETE_ARRAY_OR_OBJECT If there are no more tokens (implying the *parent*
|
||||||
* array or object is incomplete).
|
* array or object is incomplete). An INCOMPLETE_ARRAY_OR_OBJECT is an unrecoverable error that
|
||||||
|
* invalidates the document.
|
||||||
*/
|
*/
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<bool> started_root_object() noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<bool> started_root_object() noexcept;
|
||||||
|
|
||||||
@@ -257,7 +259,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @returns Whether the array had any elements (returns false for empty).
|
* @returns Whether the array had any elements (returns false for empty).
|
||||||
* @error INCOMPLETE_ARRAY_OR_OBJECT If there are no more tokens (implying the *parent*
|
* @error INCOMPLETE_ARRAY_OR_OBJECT If there are no more tokens (implying the *parent*
|
||||||
* array or object is incomplete).
|
* array or object is incomplete). An INCOMPLETE_ARRAY_OR_OBJECT is an unrecoverable error that
|
||||||
|
* invalidates the document.
|
||||||
*/
|
*/
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<bool> started_array() noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<bool> started_array() noexcept;
|
||||||
/**
|
/**
|
||||||
@@ -267,7 +270,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @returns Whether the array had any elements (returns false for empty).
|
* @returns Whether the array had any elements (returns false for empty).
|
||||||
* @error INCOMPLETE_ARRAY_OR_OBJECT If there are no more tokens (implying the *parent*
|
* @error INCOMPLETE_ARRAY_OR_OBJECT If there are no more tokens (implying the *parent*
|
||||||
* array or object is incomplete).
|
* array or object is incomplete). An INCOMPLETE_ARRAY_OR_OBJECT is an unrecoverable error that
|
||||||
|
* invalidates the document.
|
||||||
*/
|
*/
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<bool> started_root_array() noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<bool> started_root_array() noexcept;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#define SIMDJSON_SIMDJSON_VERSION_H
|
#define SIMDJSON_SIMDJSON_VERSION_H
|
||||||
|
|
||||||
/** The version of simdjson being used (major.minor.revision) */
|
/** The version of simdjson being used (major.minor.revision) */
|
||||||
#define SIMDJSON_VERSION "3.12.2"
|
#define SIMDJSON_VERSION "3.12.3"
|
||||||
|
|
||||||
namespace simdjson {
|
namespace simdjson {
|
||||||
enum {
|
enum {
|
||||||
@@ -19,7 +19,7 @@ enum {
|
|||||||
/**
|
/**
|
||||||
* The revision (major.minor.REVISION) of simdjson being used.
|
* The revision (major.minor.REVISION) of simdjson being used.
|
||||||
*/
|
*/
|
||||||
SIMDJSON_VERSION_REVISION = 2
|
SIMDJSON_VERSION_REVISION = 3
|
||||||
};
|
};
|
||||||
} // namespace simdjson
|
} // namespace simdjson
|
||||||
|
|
||||||
|
|||||||
+47
-16
@@ -1,4 +1,4 @@
|
|||||||
/* auto-generated on 2025-02-14 16:11:36 -0500. Do not edit! */
|
/* auto-generated on 2025-03-27 15:01:10 -0400. Do not edit! */
|
||||||
/* including simdjson.cpp: */
|
/* including simdjson.cpp: */
|
||||||
/* begin file simdjson.cpp */
|
/* begin file simdjson.cpp */
|
||||||
#define SIMDJSON_SRC_SIMDJSON_CPP
|
#define SIMDJSON_SRC_SIMDJSON_CPP
|
||||||
@@ -2431,7 +2431,7 @@ enum error_code {
|
|||||||
SUCCESS = 0, ///< No error
|
SUCCESS = 0, ///< No error
|
||||||
CAPACITY, ///< This parser can't support a document that big
|
CAPACITY, ///< This parser can't support a document that big
|
||||||
MEMALLOC, ///< Error allocating memory, most likely out of memory
|
MEMALLOC, ///< Error allocating memory, most likely out of memory
|
||||||
TAPE_ERROR, ///< Something went wrong, this is a generic error
|
TAPE_ERROR, ///< Something went wrong, this is a generic error. Fatal/unrecoverable error.
|
||||||
DEPTH_ERROR, ///< Your document exceeds the user-specified depth limitation
|
DEPTH_ERROR, ///< Your document exceeds the user-specified depth limitation
|
||||||
STRING_ERROR, ///< Problem while parsing a string
|
STRING_ERROR, ///< Problem while parsing a string
|
||||||
T_ATOM_ERROR, ///< Problem while parsing an atom starting with the letter 't'
|
T_ATOM_ERROR, ///< Problem while parsing an atom starting with the letter 't'
|
||||||
@@ -2456,13 +2456,21 @@ enum error_code {
|
|||||||
PARSER_IN_USE, ///< parser is already in use.
|
PARSER_IN_USE, ///< parser is already in use.
|
||||||
OUT_OF_ORDER_ITERATION, ///< tried to iterate an array or object out of order (checked when SIMDJSON_DEVELOPMENT_CHECKS=1)
|
OUT_OF_ORDER_ITERATION, ///< tried to iterate an array or object out of order (checked when SIMDJSON_DEVELOPMENT_CHECKS=1)
|
||||||
INSUFFICIENT_PADDING, ///< The JSON doesn't have enough padding for simdjson to safely parse it.
|
INSUFFICIENT_PADDING, ///< The JSON doesn't have enough padding for simdjson to safely parse it.
|
||||||
INCOMPLETE_ARRAY_OR_OBJECT, ///< The document ends early.
|
INCOMPLETE_ARRAY_OR_OBJECT, ///< The document ends early. Fatal/unrecoverable error.
|
||||||
SCALAR_DOCUMENT_AS_VALUE, ///< A scalar document is treated as a value.
|
SCALAR_DOCUMENT_AS_VALUE, ///< A scalar document is treated as a value.
|
||||||
OUT_OF_BOUNDS, ///< Attempted to access location outside of document.
|
OUT_OF_BOUNDS, ///< Attempted to access location outside of document.
|
||||||
TRAILING_CONTENT, ///< Unexpected trailing content in the JSON input
|
TRAILING_CONTENT, ///< Unexpected trailing content in the JSON input
|
||||||
NUM_ERROR_CODES
|
NUM_ERROR_CODES
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some errors are fatal and invalidate the document. This function returns true if the
|
||||||
|
* error is fatal. It returns true for TAPE_ERROR and INCOMPLETE_ARRAY_OR_OBJECT.
|
||||||
|
* Once a fatal error is encountered, the on-demand document is no longer valid and
|
||||||
|
* processing should stop.
|
||||||
|
*/
|
||||||
|
inline bool is_fatal(error_code error) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It is the convention throughout the code that the macro SIMDJSON_DEVELOPMENT_CHECKS determines whether
|
* It is the convention throughout the code that the macro SIMDJSON_DEVELOPMENT_CHECKS determines whether
|
||||||
* we check for OUT_OF_ORDER_ITERATION. The logic behind it is that these errors only occurs when the code
|
* we check for OUT_OF_ORDER_ITERATION. The logic behind it is that these errors only occurs when the code
|
||||||
@@ -2765,14 +2773,30 @@ SIMDJSON_IMPL_CONCEPT(op_append, operator+=)
|
|||||||
#undef SIMDJSON_IMPL_CONCEPT
|
#undef SIMDJSON_IMPL_CONCEPT
|
||||||
} // namespace details
|
} // namespace details
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
concept string_view_like = std::is_convertible_v<T, std::string_view> &&
|
||||||
|
!std::is_convertible_v<T, const char*>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept constructible_from_string_view = std::is_constructible_v<T, std::string_view>
|
||||||
|
&& !std::is_same_v<T, std::string_view>
|
||||||
|
&& std::is_default_constructible_v<T>;
|
||||||
|
|
||||||
|
template<typename M>
|
||||||
|
concept string_view_keyed_map = string_view_like<typename M::key_type>
|
||||||
|
&& requires(std::remove_cvref_t<M>& m, typename M::key_type sv, typename M::mapped_type v) {
|
||||||
|
{ m.emplace(sv, v) } -> std::same_as<std::pair<typename M::iterator, bool>>;
|
||||||
|
};
|
||||||
|
|
||||||
/// Check if T is a container that we can append to, including:
|
/// Check if T is a container that we can append to, including:
|
||||||
/// std::vector, std::deque, std::list, std::string, ...
|
/// std::vector, std::deque, std::list, std::string, ...
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept appendable_containers =
|
concept appendable_containers =
|
||||||
details::supports_emplace_back<T> || details::supports_emplace<T> ||
|
(details::supports_emplace_back<T> || details::supports_emplace<T> ||
|
||||||
details::supports_push_back<T> || details::supports_push<T> ||
|
details::supports_push_back<T> || details::supports_push<T> ||
|
||||||
details::supports_add<T> || details::supports_append<T> ||
|
details::supports_add<T> || details::supports_append<T> ||
|
||||||
details::supports_insert<T>;
|
details::supports_insert<T>) && !string_view_keyed_map<T>;
|
||||||
|
|
||||||
/// Insert into the container however possible
|
/// Insert into the container however possible
|
||||||
template <appendable_containers T, typename... Args>
|
template <appendable_containers T, typename... Args>
|
||||||
@@ -2840,6 +2864,8 @@ concept optional_type = requires(std::remove_cvref_t<T> obj) {
|
|||||||
{ static_cast<bool>(obj) } -> std::same_as<bool>; // convertible to bool
|
{ static_cast<bool>(obj) } -> std::same_as<bool>; // convertible to bool
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace concepts
|
} // namespace concepts
|
||||||
} // namespace simdjson
|
} // namespace simdjson
|
||||||
#endif // SIMDJSON_SUPPORTS_DESERIALIZATION
|
#endif // SIMDJSON_SUPPORTS_DESERIALIZATION
|
||||||
@@ -4511,6 +4537,11 @@ extern SIMDJSON_DLLIMPORTEXPORT const uint32_t digit_to_val32[886];
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace simdjson {
|
namespace simdjson {
|
||||||
|
|
||||||
|
inline bool is_fatal(error_code error) noexcept {
|
||||||
|
return error == TAPE_ERROR || error == INCOMPLETE_ARRAY_OR_OBJECT;
|
||||||
|
}
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
// We store the error code so we can validate the error message is associated with the right code
|
// We store the error code so we can validate the error message is associated with the right code
|
||||||
struct error_code_info {
|
struct error_code_info {
|
||||||
@@ -4696,7 +4727,7 @@ namespace internal {
|
|||||||
{ SUCCESS, "SUCCESS: No error" },
|
{ SUCCESS, "SUCCESS: No error" },
|
||||||
{ CAPACITY, "CAPACITY: This parser can't support a document that big" },
|
{ CAPACITY, "CAPACITY: This parser can't support a document that big" },
|
||||||
{ MEMALLOC, "MEMALLOC: Error allocating memory, we're most likely out of memory" },
|
{ MEMALLOC, "MEMALLOC: Error allocating memory, we're most likely out of memory" },
|
||||||
{ TAPE_ERROR, "TAPE_ERROR: The JSON document has an improper structure: missing or superfluous commas, braces, missing keys, etc." },
|
{ TAPE_ERROR, "TAPE_ERROR: The JSON document has an improper structure: missing or superfluous commas, braces, missing keys, etc. This is a fatal and unrecoverable error." },
|
||||||
{ DEPTH_ERROR, "DEPTH_ERROR: The JSON document was too deep (too many nested objects and arrays)" },
|
{ DEPTH_ERROR, "DEPTH_ERROR: The JSON document was too deep (too many nested objects and arrays)" },
|
||||||
{ STRING_ERROR, "STRING_ERROR: Problem while parsing a string" },
|
{ STRING_ERROR, "STRING_ERROR: Problem while parsing a string" },
|
||||||
{ T_ATOM_ERROR, "T_ATOM_ERROR: Problem while parsing an atom starting with the letter 't'" },
|
{ T_ATOM_ERROR, "T_ATOM_ERROR: Problem while parsing an atom starting with the letter 't'" },
|
||||||
@@ -4721,7 +4752,7 @@ namespace internal {
|
|||||||
{ PARSER_IN_USE, "PARSER_IN_USE: Cannot parse a new document while a document is still in use." },
|
{ PARSER_IN_USE, "PARSER_IN_USE: Cannot parse a new document while a document is still in use." },
|
||||||
{ OUT_OF_ORDER_ITERATION, "OUT_OF_ORDER_ITERATION: Objects and arrays can only be iterated when they are first encountered." },
|
{ OUT_OF_ORDER_ITERATION, "OUT_OF_ORDER_ITERATION: Objects and arrays can only be iterated when they are first encountered." },
|
||||||
{ INSUFFICIENT_PADDING, "INSUFFICIENT_PADDING: simdjson requires the input JSON string to have at least SIMDJSON_PADDING extra bytes allocated, beyond the string's length. Consider using the simdjson::padded_string class if needed." },
|
{ INSUFFICIENT_PADDING, "INSUFFICIENT_PADDING: simdjson requires the input JSON string to have at least SIMDJSON_PADDING extra bytes allocated, beyond the string's length. Consider using the simdjson::padded_string class if needed." },
|
||||||
{ INCOMPLETE_ARRAY_OR_OBJECT, "INCOMPLETE_ARRAY_OR_OBJECT: JSON document ended early in the middle of an object or array." },
|
{ INCOMPLETE_ARRAY_OR_OBJECT, "INCOMPLETE_ARRAY_OR_OBJECT: JSON document ended early in the middle of an object or array. This is a fatal and unrecoverable error." },
|
||||||
{ SCALAR_DOCUMENT_AS_VALUE, "SCALAR_DOCUMENT_AS_VALUE: A JSON document made of a scalar (number, Boolean, null or string) is treated as a value. Use get_bool(), get_double(), etc. on the document instead. "},
|
{ SCALAR_DOCUMENT_AS_VALUE, "SCALAR_DOCUMENT_AS_VALUE: A JSON document made of a scalar (number, Boolean, null or string) is treated as a value. Use get_bool(), get_double(), etc. on the document instead. "},
|
||||||
{ OUT_OF_BOUNDS, "OUT_OF_BOUNDS: Attempt to access location outside of document."},
|
{ OUT_OF_BOUNDS, "OUT_OF_BOUNDS: Attempt to access location outside of document."},
|
||||||
{ TRAILING_CONTENT, "TRAILING_CONTENT: Unexpected trailing content in the JSON input."}
|
{ TRAILING_CONTENT, "TRAILING_CONTENT: Unexpected trailing content in the JSON input."}
|
||||||
@@ -6787,7 +6818,7 @@ public:
|
|||||||
* The memory allocation is strict: you
|
* The memory allocation is strict: you
|
||||||
* can you use this function to increase
|
* can you use this function to increase
|
||||||
* or lower the amount of allocated memory.
|
* or lower the amount of allocated memory.
|
||||||
* Passsing zero clears the memory.
|
* Passing zero clears the memory.
|
||||||
*/
|
*/
|
||||||
error_code allocate(size_t len) noexcept;
|
error_code allocate(size_t len) noexcept;
|
||||||
/** @private Capacity in bytes, in terms
|
/** @private Capacity in bytes, in terms
|
||||||
@@ -9185,7 +9216,7 @@ simdjson_inline bool compute_float_64(int64_t power, uint64_t i, bool negative,
|
|||||||
// floor(log(5**power)/log(2))
|
// floor(log(5**power)/log(2))
|
||||||
//
|
//
|
||||||
// Note that this is not magic: 152170/(1<<16) is
|
// Note that this is not magic: 152170/(1<<16) is
|
||||||
// approximatively equal to log(5)/log(2).
|
// approximately equal to log(5)/log(2).
|
||||||
// The 1<<16 value is a power of two; we could use a
|
// The 1<<16 value is a power of two; we could use a
|
||||||
// larger power of 2 if we wanted to.
|
// larger power of 2 if we wanted to.
|
||||||
//
|
//
|
||||||
@@ -15545,7 +15576,7 @@ simdjson_inline bool compute_float_64(int64_t power, uint64_t i, bool negative,
|
|||||||
// floor(log(5**power)/log(2))
|
// floor(log(5**power)/log(2))
|
||||||
//
|
//
|
||||||
// Note that this is not magic: 152170/(1<<16) is
|
// Note that this is not magic: 152170/(1<<16) is
|
||||||
// approximatively equal to log(5)/log(2).
|
// approximately equal to log(5)/log(2).
|
||||||
// The 1<<16 value is a power of two; we could use a
|
// The 1<<16 value is a power of two; we could use a
|
||||||
// larger power of 2 if we wanted to.
|
// larger power of 2 if we wanted to.
|
||||||
//
|
//
|
||||||
@@ -21769,7 +21800,7 @@ simdjson_inline bool compute_float_64(int64_t power, uint64_t i, bool negative,
|
|||||||
// floor(log(5**power)/log(2))
|
// floor(log(5**power)/log(2))
|
||||||
//
|
//
|
||||||
// Note that this is not magic: 152170/(1<<16) is
|
// Note that this is not magic: 152170/(1<<16) is
|
||||||
// approximatively equal to log(5)/log(2).
|
// approximately equal to log(5)/log(2).
|
||||||
// The 1<<16 value is a power of two; we could use a
|
// The 1<<16 value is a power of two; we could use a
|
||||||
// larger power of 2 if we wanted to.
|
// larger power of 2 if we wanted to.
|
||||||
//
|
//
|
||||||
@@ -28149,7 +28180,7 @@ simdjson_inline bool compute_float_64(int64_t power, uint64_t i, bool negative,
|
|||||||
// floor(log(5**power)/log(2))
|
// floor(log(5**power)/log(2))
|
||||||
//
|
//
|
||||||
// Note that this is not magic: 152170/(1<<16) is
|
// Note that this is not magic: 152170/(1<<16) is
|
||||||
// approximatively equal to log(5)/log(2).
|
// approximately equal to log(5)/log(2).
|
||||||
// The 1<<16 value is a power of two; we could use a
|
// The 1<<16 value is a power of two; we could use a
|
||||||
// larger power of 2 if we wanted to.
|
// larger power of 2 if we wanted to.
|
||||||
//
|
//
|
||||||
@@ -34891,7 +34922,7 @@ simdjson_inline bool compute_float_64(int64_t power, uint64_t i, bool negative,
|
|||||||
// floor(log(5**power)/log(2))
|
// floor(log(5**power)/log(2))
|
||||||
//
|
//
|
||||||
// Note that this is not magic: 152170/(1<<16) is
|
// Note that this is not magic: 152170/(1<<16) is
|
||||||
// approximatively equal to log(5)/log(2).
|
// approximately equal to log(5)/log(2).
|
||||||
// The 1<<16 value is a power of two; we could use a
|
// The 1<<16 value is a power of two; we could use a
|
||||||
// larger power of 2 if we wanted to.
|
// larger power of 2 if we wanted to.
|
||||||
//
|
//
|
||||||
@@ -41457,7 +41488,7 @@ simdjson_inline bool compute_float_64(int64_t power, uint64_t i, bool negative,
|
|||||||
// floor(log(5**power)/log(2))
|
// floor(log(5**power)/log(2))
|
||||||
//
|
//
|
||||||
// Note that this is not magic: 152170/(1<<16) is
|
// Note that this is not magic: 152170/(1<<16) is
|
||||||
// approximatively equal to log(5)/log(2).
|
// approximately equal to log(5)/log(2).
|
||||||
// The 1<<16 value is a power of two; we could use a
|
// The 1<<16 value is a power of two; we could use a
|
||||||
// larger power of 2 if we wanted to.
|
// larger power of 2 if we wanted to.
|
||||||
//
|
//
|
||||||
@@ -47468,7 +47499,7 @@ simdjson_inline bool compute_float_64(int64_t power, uint64_t i, bool negative,
|
|||||||
// floor(log(5**power)/log(2))
|
// floor(log(5**power)/log(2))
|
||||||
//
|
//
|
||||||
// Note that this is not magic: 152170/(1<<16) is
|
// Note that this is not magic: 152170/(1<<16) is
|
||||||
// approximatively equal to log(5)/log(2).
|
// approximately equal to log(5)/log(2).
|
||||||
// The 1<<16 value is a power of two; we could use a
|
// The 1<<16 value is a power of two; we could use a
|
||||||
// larger power of 2 if we wanted to.
|
// larger power of 2 if we wanted to.
|
||||||
//
|
//
|
||||||
@@ -53078,7 +53109,7 @@ simdjson_inline bool compute_float_64(int64_t power, uint64_t i, bool negative,
|
|||||||
// floor(log(5**power)/log(2))
|
// floor(log(5**power)/log(2))
|
||||||
//
|
//
|
||||||
// Note that this is not magic: 152170/(1<<16) is
|
// Note that this is not magic: 152170/(1<<16) is
|
||||||
// approximatively equal to log(5)/log(2).
|
// approximately equal to log(5)/log(2).
|
||||||
// The 1<<16 value is a power of two; we could use a
|
// The 1<<16 value is a power of two; we could use a
|
||||||
// larger power of 2 if we wanted to.
|
// larger power of 2 if we wanted to.
|
||||||
//
|
//
|
||||||
|
|||||||
+1001
-402
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,7 @@ namespace internal {
|
|||||||
{ SUCCESS, "SUCCESS: No error" },
|
{ SUCCESS, "SUCCESS: No error" },
|
||||||
{ CAPACITY, "CAPACITY: This parser can't support a document that big" },
|
{ CAPACITY, "CAPACITY: This parser can't support a document that big" },
|
||||||
{ MEMALLOC, "MEMALLOC: Error allocating memory, we're most likely out of memory" },
|
{ MEMALLOC, "MEMALLOC: Error allocating memory, we're most likely out of memory" },
|
||||||
{ TAPE_ERROR, "TAPE_ERROR: The JSON document has an improper structure: missing or superfluous commas, braces, missing keys, etc." },
|
{ TAPE_ERROR, "TAPE_ERROR: The JSON document has an improper structure: missing or superfluous commas, braces, missing keys, etc. This is a fatal and unrecoverable error." },
|
||||||
{ DEPTH_ERROR, "DEPTH_ERROR: The JSON document was too deep (too many nested objects and arrays)" },
|
{ DEPTH_ERROR, "DEPTH_ERROR: The JSON document was too deep (too many nested objects and arrays)" },
|
||||||
{ STRING_ERROR, "STRING_ERROR: Problem while parsing a string" },
|
{ STRING_ERROR, "STRING_ERROR: Problem while parsing a string" },
|
||||||
{ T_ATOM_ERROR, "T_ATOM_ERROR: Problem while parsing an atom starting with the letter 't'" },
|
{ T_ATOM_ERROR, "T_ATOM_ERROR: Problem while parsing an atom starting with the letter 't'" },
|
||||||
@@ -36,7 +36,7 @@ namespace internal {
|
|||||||
{ PARSER_IN_USE, "PARSER_IN_USE: Cannot parse a new document while a document is still in use." },
|
{ PARSER_IN_USE, "PARSER_IN_USE: Cannot parse a new document while a document is still in use." },
|
||||||
{ OUT_OF_ORDER_ITERATION, "OUT_OF_ORDER_ITERATION: Objects and arrays can only be iterated when they are first encountered." },
|
{ OUT_OF_ORDER_ITERATION, "OUT_OF_ORDER_ITERATION: Objects and arrays can only be iterated when they are first encountered." },
|
||||||
{ INSUFFICIENT_PADDING, "INSUFFICIENT_PADDING: simdjson requires the input JSON string to have at least SIMDJSON_PADDING extra bytes allocated, beyond the string's length. Consider using the simdjson::padded_string class if needed." },
|
{ INSUFFICIENT_PADDING, "INSUFFICIENT_PADDING: simdjson requires the input JSON string to have at least SIMDJSON_PADDING extra bytes allocated, beyond the string's length. Consider using the simdjson::padded_string class if needed." },
|
||||||
{ INCOMPLETE_ARRAY_OR_OBJECT, "INCOMPLETE_ARRAY_OR_OBJECT: JSON document ended early in the middle of an object or array." },
|
{ INCOMPLETE_ARRAY_OR_OBJECT, "INCOMPLETE_ARRAY_OR_OBJECT: JSON document ended early in the middle of an object or array. This is a fatal and unrecoverable error." },
|
||||||
{ SCALAR_DOCUMENT_AS_VALUE, "SCALAR_DOCUMENT_AS_VALUE: A JSON document made of a scalar (number, Boolean, null or string) is treated as a value. Use get_bool(), get_double(), etc. on the document instead. "},
|
{ SCALAR_DOCUMENT_AS_VALUE, "SCALAR_DOCUMENT_AS_VALUE: A JSON document made of a scalar (number, Boolean, null or string) is treated as a value. Use get_bool(), get_double(), etc. on the document instead. "},
|
||||||
{ OUT_OF_BOUNDS, "OUT_OF_BOUNDS: Attempt to access location outside of document."},
|
{ OUT_OF_BOUNDS, "OUT_OF_BOUNDS: Attempt to access location outside of document."},
|
||||||
{ TRAILING_CONTENT, "TRAILING_CONTENT: Unexpected trailing content in the JSON input."}
|
{ TRAILING_CONTENT, "TRAILING_CONTENT: Unexpected trailing content in the JSON input."}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <map>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
using namespace simdjson;
|
using namespace simdjson;
|
||||||
|
|
||||||
@@ -238,6 +240,40 @@ bool optional_car_deserialize() {
|
|||||||
TEST_SUCCEED();
|
TEST_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool car_deserialize_to_map() {
|
||||||
|
TEST_START();
|
||||||
|
std::map<std::string,std::string> expected = { {"make", "Toyota"}, {"model", "Camry"}};
|
||||||
|
padded_string json =
|
||||||
|
R"( { "make": "Toyota", "model": "Camry" })"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document doc;
|
||||||
|
[[maybe_unused]] auto error = parser.iterate(json).get(doc);
|
||||||
|
static_assert(simdjson::concepts::string_view_keyed_map<std::map<std::string, std::string>>, "should be custom deserializable");
|
||||||
|
using map_type = typename std::map<std::string,std::string>;
|
||||||
|
static_assert(simdjson::custom_deserializable<map_type,simdjson::ondemand::value>, "should be custom deserializable");
|
||||||
|
map_type brands;
|
||||||
|
error = doc.get<map_type>().get(brands);
|
||||||
|
ASSERT_TRUE(brands == expected);
|
||||||
|
TEST_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool car_deserialize_with_map() {
|
||||||
|
TEST_START();
|
||||||
|
padded_string json =
|
||||||
|
R"( { "car1": { "make": "Toyota", "model": "Camry", "year": 2018,
|
||||||
|
"tire_pressure": [ 40.1, 39.9 ] }
|
||||||
|
})"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document doc;
|
||||||
|
[[maybe_unused]] auto error = parser.iterate(json).get(doc);
|
||||||
|
std::map<std::string,Car> car;
|
||||||
|
error = doc.get<std::map<std::string,Car>>().get(car);
|
||||||
|
std::optional<Car> expected = Car{"Toyota", "Camry", 2018, {40.1f, 39.9f}};
|
||||||
|
ASSERT_TRUE(car["car1"] == expected);
|
||||||
|
TEST_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
bool car_doc_deserialize() {
|
bool car_doc_deserialize() {
|
||||||
TEST_START();
|
TEST_START();
|
||||||
padded_string json = R"( { "make": "Toyota", "model": "Camry", "year": 2018,
|
padded_string json = R"( { "make": "Toyota", "model": "Camry", "year": 2018,
|
||||||
@@ -320,7 +356,9 @@ bool car_unique_ptr_deserialize() {
|
|||||||
TEST_SUCCEED();
|
TEST_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool run() { return list_car_deserialize()
|
bool run() { return car_deserialize_with_map()
|
||||||
|
&& car_deserialize_to_map()
|
||||||
|
&& list_car_deserialize()
|
||||||
&& optional_car_deserialize()
|
&& optional_car_deserialize()
|
||||||
&& car_unique_ptr_deserialize()
|
&& car_unique_ptr_deserialize()
|
||||||
&& vector_car_deserialize()
|
&& vector_car_deserialize()
|
||||||
|
|||||||
@@ -5,23 +5,51 @@ using namespace simdjson;
|
|||||||
|
|
||||||
namespace misc_tests {
|
namespace misc_tests {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
bool issue2322() {
|
bool issue2354() {
|
||||||
TEST_START();
|
TEST_START();
|
||||||
std::vector<std::pair<std::string, bool>> examples = {{R"("hello")", false},
|
auto json = "true "_padded;
|
||||||
{R"(\"hello)", true},
|
ondemand::parser parser;
|
||||||
{R"("hello\")", true},
|
ondemand::document doc;
|
||||||
{R"("hel\"lo")", false},
|
ASSERT_SUCCESS(parser.iterate(json).get(doc));
|
||||||
{R"("hel\\lo")", false},
|
bool b;
|
||||||
{R"(\"hel\\\"lo\")", true},
|
ASSERT_SUCCESS(doc.get_bool().get(b));
|
||||||
{R"(\\"hel\\\"lo\")", false}};
|
ASSERT_TRUE(b);
|
||||||
for (std::pair<std::string, bool> v : examples) {
|
TEST_SUCCEED();
|
||||||
ASSERT_EQUAL(ondemand::raw_json_string::is_free_from_unescaped_quote(v.first),
|
}
|
||||||
v.second);
|
bool issue2355() {
|
||||||
ASSERT_EQUAL(ondemand::raw_json_string::is_free_from_unescaped_quote(v.first.c_str()),
|
TEST_START();
|
||||||
v.second);
|
simdjson::ondemand::parser parser;
|
||||||
|
auto json = "[\"extra close\"]]"_padded;
|
||||||
|
ondemand::document doc;
|
||||||
|
ASSERT_SUCCESS(parser.iterate(json).get(doc));
|
||||||
|
simdjson::ondemand::array test;
|
||||||
|
ASSERT_SUCCESS(doc.get_array().get(test));
|
||||||
|
for(auto vale : test) {
|
||||||
|
std::string_view str;
|
||||||
|
ASSERT_SUCCESS(vale.get_string().get(str));
|
||||||
|
ASSERT_EQUAL(str, "extra close");
|
||||||
|
}
|
||||||
|
ASSERT_FALSE(doc.at_end());
|
||||||
|
TEST_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool issue2322() {
|
||||||
|
TEST_START();
|
||||||
|
std::vector<std::pair<std::string, bool>> examples = {{R"("hello")", false},
|
||||||
|
{R"(\"hello)", true},
|
||||||
|
{R"("hello\")", true},
|
||||||
|
{R"("hel\"lo")", false},
|
||||||
|
{R"("hel\\lo")", false},
|
||||||
|
{R"(\"hel\\\"lo\")", true},
|
||||||
|
{R"(\\"hel\\\"lo\")", false}};
|
||||||
|
for (std::pair<std::string, bool> v : examples) {
|
||||||
|
ASSERT_EQUAL(ondemand::raw_json_string::is_free_from_unescaped_quote(v.first),
|
||||||
|
v.second);
|
||||||
|
ASSERT_EQUAL(ondemand::raw_json_string::is_free_from_unescaped_quote(v.first.c_str()),
|
||||||
|
v.second);
|
||||||
|
}
|
||||||
|
TEST_SUCCEED();
|
||||||
}
|
}
|
||||||
TEST_SUCCEED();
|
|
||||||
}
|
|
||||||
#if SIMDJSON_EXCEPTIONS
|
#if SIMDJSON_EXCEPTIONS
|
||||||
// user reported an asan error:
|
// user reported an asan error:
|
||||||
bool issue2199() {
|
bool issue2199() {
|
||||||
@@ -655,6 +683,8 @@ bool issue2322() {
|
|||||||
|
|
||||||
bool run() {
|
bool run() {
|
||||||
return
|
return
|
||||||
|
issue2355() &&
|
||||||
|
issue2354() &&
|
||||||
issue2322() &&
|
issue2322() &&
|
||||||
issue2312() &&
|
issue2312() &&
|
||||||
#if SIMDJSON_EXCEPTIONS
|
#if SIMDJSON_EXCEPTIONS
|
||||||
|
|||||||
@@ -10,6 +10,20 @@ using namespace std;
|
|||||||
using namespace simdjson;
|
using namespace simdjson;
|
||||||
using error_code = simdjson::error_code;
|
using error_code = simdjson::error_code;
|
||||||
|
|
||||||
|
bool fatal_error() {
|
||||||
|
TEST_START();
|
||||||
|
padded_string badjson = R"( { "make": "Toyota", "model": "Camry", "year"})"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document doc;
|
||||||
|
auto errordoc = parser.iterate(badjson).get(doc);
|
||||||
|
if(errordoc != simdjson::SUCCESS) { return false; }
|
||||||
|
simdjson::ondemand::value v;
|
||||||
|
auto error = doc.get_object()["year"].get(v);
|
||||||
|
ASSERT_TRUE(simdjson::is_fatal(error));
|
||||||
|
ASSERT_FALSE(doc.is_alive());
|
||||||
|
TEST_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
bool simplepad() {
|
bool simplepad() {
|
||||||
std::string json = "[1]";
|
std::string json = "[1]";
|
||||||
ondemand::parser parser;
|
ondemand::parser parser;
|
||||||
@@ -22,14 +36,14 @@ bool string1() {
|
|||||||
const char * data = "my data"; // 7 bytes
|
const char * data = "my data"; // 7 bytes
|
||||||
simdjson::padded_string my_padded_data(data, 7); // copies to a padded buffer
|
simdjson::padded_string my_padded_data(data, 7); // copies to a padded buffer
|
||||||
std::cout << my_padded_data << std::endl;
|
std::cout << my_padded_data << std::endl;
|
||||||
return true;
|
TEST_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool string2() {
|
bool string2() {
|
||||||
std::string data = "my data";
|
std::string data = "my data";
|
||||||
simdjson::padded_string my_padded_data(data); // copies to a padded buffer
|
simdjson::padded_string my_padded_data(data); // copies to a padded buffer
|
||||||
std::cout << my_padded_data << std::endl;
|
std::cout << my_padded_data << std::endl;
|
||||||
return true;
|
TEST_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool to_string_example_no_except() {
|
bool to_string_example_no_except() {
|
||||||
@@ -272,6 +286,22 @@ bool at_end() {
|
|||||||
TEST_SUCCEED();
|
TEST_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool at_end_array() {
|
||||||
|
TEST_START();
|
||||||
|
auto json = R"(["extra close"]])"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document doc = parser.iterate(json);
|
||||||
|
ondemand::array array = doc.get_array();
|
||||||
|
for (std::string_view values : array) {
|
||||||
|
std::cout << values << std::endl;
|
||||||
|
}
|
||||||
|
if(!doc.at_end()) {
|
||||||
|
std::cerr << "trailing content at byte index " << doc.current_location() - json.data() << std::endl;
|
||||||
|
}
|
||||||
|
TEST_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
bool examplecrt() {
|
bool examplecrt() {
|
||||||
TEST_START();
|
TEST_START();
|
||||||
padded_string padded_input_json = R"([
|
padded_string padded_input_json = R"([
|
||||||
@@ -1893,6 +1923,7 @@ bool value_raw_json_object() {
|
|||||||
#endif
|
#endif
|
||||||
bool run() {
|
bool run() {
|
||||||
return true
|
return true
|
||||||
|
&& fatal_error()
|
||||||
#if SIMDJSON_EXCEPTIONS
|
#if SIMDJSON_EXCEPTIONS
|
||||||
#if SIMDJSON_CPLUSPLUS17
|
#if SIMDJSON_CPLUSPLUS17
|
||||||
&& big_int_array()
|
&& big_int_array()
|
||||||
@@ -1956,8 +1987,9 @@ bool run() {
|
|||||||
&& current_location_tape_error_with_except()
|
&& current_location_tape_error_with_except()
|
||||||
&& examplecrt()
|
&& examplecrt()
|
||||||
&& examplecrt_realloc()
|
&& examplecrt_realloc()
|
||||||
|
&& at_end_array()
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user