Compare commits
62 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e85352df4 | |||
| fc57c09cf0 | |||
| 2058b47dfe | |||
| b0486c7fa2 | |||
| feb1e7feb6 | |||
| 2c7fbc1538 | |||
| 8b69401d8a | |||
| f504e57e7a | |||
| 135c173053 | |||
| b4ed3a99a9 | |||
| d8e1b36c88 | |||
| c249a1b456 | |||
| 9c4b793c90 | |||
| dd92a8414c | |||
| 835bdba123 | |||
| ad3cd71ca2 | |||
| 860f7e0458 | |||
| 980f2ad3af | |||
| 7ad9fe63a6 | |||
| 7987418b1f | |||
| 5e871f6724 | |||
| 5d16fd5f31 | |||
| 4e9ff03af5 | |||
| aa7489060a | |||
| ae32422891 | |||
| 667d0ed3c7 | |||
| b1c31b428d | |||
| 56ac56ba32 | |||
| 19549c60ec | |||
| 16e99f229b | |||
| 21342a4142 | |||
| d0e841d3e9 | |||
| a962652ec3 | |||
| 77d73b068a | |||
| 19ff7a572d | |||
| 235dbc5369 | |||
| 2b9c8977af | |||
| 3d87bd4abc | |||
| a60c0d1e39 | |||
| 86bfbaada7 | |||
| ccac6403d9 | |||
| aade58c3dc | |||
| 3319815e25 | |||
| a24f845bd7 | |||
| 212e2d5857 | |||
| 547e156e33 | |||
| 98a45f7229 | |||
| 8589509d1e | |||
| 2fce4a843d | |||
| 62803512e4 | |||
| 76d9dee854 | |||
| bf15f21b0b | |||
| 32b301893c | |||
| 7f1531a1f9 | |||
| 0a3b555ff7 | |||
| 114d45ad54 | |||
| bf52d8198b | |||
| def2b6efd2 | |||
| d326f2ce9f | |||
| ca42a49fba | |||
| 403b8bfb91 | |||
| 76f45a0c4b |
@@ -38,7 +38,7 @@ If we cannot reproduce the issue, then we cannot address it. Note that a stack t
|
|||||||
|
|
||||||
It should be possible to trigger the bug by using solely simdjson with our default build setup. If you can only observe the bug within some specific context, with some other software, please reduce the issue first.
|
It should be possible to trigger the bug by using solely simdjson with our default build setup. If you can only observe the bug within some specific context, with some other software, please reduce the issue first.
|
||||||
|
|
||||||
**simjson release**
|
**simdjson release**
|
||||||
|
|
||||||
Unless you plan to contribute to simdjson, you should only work from releases. Please be mindful that our main branch may have additional features, bugs and documentation items.
|
Unless you plan to contribute to simdjson, you should only work from releases. Please be mindful that our main branch may have additional features, bugs and documentation items.
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Description
|
|||||||
|
|
||||||
Type of change
|
Type of change
|
||||||
- [ ] Bug fix
|
- [ ] Bug fix
|
||||||
|
- [ ] Optimization
|
||||||
- [ ] New feature
|
- [ ] New feature
|
||||||
- [ ] Refactor / cleanup
|
- [ ] Refactor / cleanup
|
||||||
- [ ] Documentation / tests
|
- [ ] Documentation / tests
|
||||||
|
|||||||
@@ -1,9 +1,18 @@
|
|||||||
cmake_minimum_required(VERSION 3.14)
|
cmake_minimum_required(VERSION 3.14)
|
||||||
|
|
||||||
|
# Build performance optimizations
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "Export compile commands for faster IDE integration")
|
||||||
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||||
|
|
||||||
|
# Enable parallel compilation on MSVC
|
||||||
|
if(MSVC)
|
||||||
|
add_compile_options(/MP)
|
||||||
|
endif()
|
||||||
|
|
||||||
project(
|
project(
|
||||||
simdjson
|
simdjson
|
||||||
# The version number is modified by tools/release.py
|
# The version number is modified by tools/release.py
|
||||||
VERSION 4.1.0
|
VERSION 4.2.4
|
||||||
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
|
||||||
@@ -20,8 +29,8 @@ string(
|
|||||||
# ---- Options, variables ----
|
# ---- Options, variables ----
|
||||||
|
|
||||||
# These version numbers are modified by tools/release.py
|
# These version numbers are modified by tools/release.py
|
||||||
set(SIMDJSON_LIB_VERSION "28.0.0" CACHE STRING "simdjson library version")
|
set(SIMDJSON_LIB_VERSION "29.0.0" CACHE STRING "simdjson library version")
|
||||||
set(SIMDJSON_LIB_SOVERSION "28" CACHE STRING "simdjson library soversion")
|
set(SIMDJSON_LIB_SOVERSION "29" CACHE STRING "simdjson library soversion")
|
||||||
|
|
||||||
option(SIMDJSON_BUILD_STATIC_LIB "Build simdjson_static library along with simdjson (only makes sense if BUILD_SHARED_LIBS=ON)" OFF)
|
option(SIMDJSON_BUILD_STATIC_LIB "Build simdjson_static library along with simdjson (only makes sense if BUILD_SHARED_LIBS=ON)" OFF)
|
||||||
if(SIMDJSON_BUILD_STATIC_LIB AND NOT BUILD_SHARED_LIBS)
|
if(SIMDJSON_BUILD_STATIC_LIB AND NOT BUILD_SHARED_LIBS)
|
||||||
@@ -83,10 +92,36 @@ add_library(simdjson ${SIMDJSON_SOURCES})
|
|||||||
add_library(simdjson::simdjson ALIAS simdjson)
|
add_library(simdjson::simdjson ALIAS simdjson)
|
||||||
set(SIMDJSON_LIBRARIES simdjson)
|
set(SIMDJSON_LIBRARIES simdjson)
|
||||||
|
|
||||||
|
# Enable precompiled headers for faster builds
|
||||||
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.16")
|
||||||
|
target_precompile_headers(simdjson PRIVATE
|
||||||
|
<algorithm>
|
||||||
|
<array>
|
||||||
|
<atomic>
|
||||||
|
<bit>
|
||||||
|
<cassert>
|
||||||
|
<cctype>
|
||||||
|
<cerrno>
|
||||||
|
<cstddef>
|
||||||
|
<cstdint>
|
||||||
|
<cstdlib>
|
||||||
|
<cstring>
|
||||||
|
<memory>
|
||||||
|
<string>
|
||||||
|
<utility>
|
||||||
|
<vector>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(SIMDJSON_BUILD_STATIC_LIB)
|
if(SIMDJSON_BUILD_STATIC_LIB)
|
||||||
add_library(simdjson_static STATIC ${SIMDJSON_SOURCES})
|
add_library(simdjson_static STATIC ${SIMDJSON_SOURCES})
|
||||||
add_library(simdjson::simdjson_static ALIAS simdjson_static)
|
add_library(simdjson::simdjson_static ALIAS simdjson_static)
|
||||||
list(APPEND SIMDJSON_LIBRARIES simdjson_static)
|
list(APPEND SIMDJSON_LIBRARIES simdjson_static)
|
||||||
|
|
||||||
|
# Reuse precompiled headers for static library
|
||||||
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.16")
|
||||||
|
target_precompile_headers(simdjson_static REUSE_FROM simdjson)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
@@ -112,6 +147,14 @@ simdjson_add_props(
|
|||||||
PRIVATE "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
|
PRIVATE "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Optimize linker settings for faster builds
|
||||||
|
if(MSVC)
|
||||||
|
target_link_options(simdjson PRIVATE /INCREMENTAL)
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
target_link_options(simdjson PRIVATE /DEBUG:FASTLINK)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
if(SIMDJSON_STATIC_REFLECTION)
|
if(SIMDJSON_STATIC_REFLECTION)
|
||||||
# We would like to require C++26, but no compiler supports that!
|
# We would like to require C++26, but no compiler supports that!
|
||||||
# This is a hack:
|
# This is a hack:
|
||||||
@@ -140,24 +183,6 @@ if(SIMDJSON_MINUS_ZERO_AS_FLOAT)
|
|||||||
simdjson_add_props(target_compile_definitions PRIVATE SIMDJSON_MINUS_ZERO_AS_FLOAT=1)
|
simdjson_add_props(target_compile_definitions PRIVATE SIMDJSON_MINUS_ZERO_AS_FLOAT=1)
|
||||||
endif(SIMDJSON_MINUS_ZERO_AS_FLOAT)
|
endif(SIMDJSON_MINUS_ZERO_AS_FLOAT)
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(loongarch64)$")
|
|
||||||
option(SIMDJSON_PREFER_LSX "Prefer LoongArch SX" ON)
|
|
||||||
include(CheckCXXCompilerFlag)
|
|
||||||
check_cxx_compiler_flag(-mlasx COMPILER_SUPPORTS_LASX)
|
|
||||||
check_cxx_compiler_flag(-mlsx COMPILER_SUPPORTS_LSX)
|
|
||||||
if(COMPILER_SUPPORTS_LASX AND NOT SIMDJSON_PREFER_LSX)
|
|
||||||
simdjson_add_props(
|
|
||||||
target_compile_options PRIVATE
|
|
||||||
-mlasx
|
|
||||||
)
|
|
||||||
elseif(COMPILER_SUPPORTS_LSX)
|
|
||||||
simdjson_add_props(
|
|
||||||
target_compile_options PRIVATE
|
|
||||||
-mlsx
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# GCC and Clang have horrendous Debug builds when using SIMD.
|
# GCC and Clang have horrendous Debug builds when using SIMD.
|
||||||
# A common fix is to use '-Og' instead.
|
# A common fix is to use '-Og' instead.
|
||||||
# bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54412
|
# bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54412
|
||||||
@@ -171,7 +196,12 @@ if(
|
|||||||
target_compile_options PRIVATE
|
target_compile_options PRIVATE
|
||||||
$<$<CONFIG:DEBUG>:-Og>
|
$<$<CONFIG:DEBUG>:-Og>
|
||||||
)
|
)
|
||||||
endif()
|
# We still want to enable development checks in Debug mode
|
||||||
|
simdjson_add_props(
|
||||||
|
target_compile_definitions PUBLIC
|
||||||
|
SIMDJSON_DEVELOPMENT_CHECKS
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(SIMDJSON_ENABLE_THREADS)
|
if(SIMDJSON_ENABLE_THREADS)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|||||||
@@ -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 = "4.1.0"
|
PROJECT_NUMBER = "4.2.4"
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
@@ -110,6 +110,24 @@ workflows used by simdjson.
|
|||||||
Directory Structure and Source
|
Directory Structure and Source
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|
||||||
|
Before diving into the directory structure, here are key concepts used in the codebase:
|
||||||
|
|
||||||
|
- **Amalgamated File**: A file that is conditionally included in the amalgamation process. These are wrapped in `#ifndef SIMDJSON_CONDITIONAL_INCLUDE` blocks and are included based on the target implementation (e.g., ARM64, x86). They include implementation-specific files (e.g., `arm64.h`) and generic files (e.g., under `generic/`). Amalgamated files have associated dependency files (`dependencies.h`) to track includes.
|
||||||
|
|
||||||
|
- **Amalgamator File**: A file that orchestrates the inclusion of amalgamated files. Examples: `arm64.h`, `arm64/implementation.h`, `generic/amalgamated.h`. These are not themselves amalgamated but control conditional inclusions.
|
||||||
|
|
||||||
|
- **Free Dependency File**: A top-level header that is always included unconditionally. These do not have dependency files and represent the public API (e.g., main headers).
|
||||||
|
|
||||||
|
- **Implementation-Specific File**: A file tied to a specific CPU architecture or instruction set (e.g., `arm64/`, `haswell/`). These must be amalgamated.
|
||||||
|
|
||||||
|
- **Generic File**: A shared file (under `generic/` or `simdjson/generic/`) that contains common code included once per implementation.
|
||||||
|
|
||||||
|
- **Builtin File**: Special files under `simdjson/builtin/` that handle the builtin implementation, a fallback/default implementation used when no optimized implementation is available.
|
||||||
|
|
||||||
|
- **Conditional Include Block**: A section wrapped in `#ifndef SIMDJSON_CONDITIONAL_INCLUDE` for editor-only or implementation-specific content.
|
||||||
|
|
||||||
|
The script `singleheader/amalgation_helper.py` will generate an HTML report which you can use to visualize the status of each file.
|
||||||
|
|
||||||
simdjson's source structure, from the top level, looks like this:
|
simdjson's source structure, from the top level, looks like this:
|
||||||
|
|
||||||
* **CMakeLists.txt:** The main build system.
|
* **CMakeLists.txt:** The main build system.
|
||||||
@@ -133,6 +151,12 @@ simdjson's source structure, from the top level, looks like this:
|
|||||||
* simdjson/generic/ondemand/*.h: individual On-Demand classes, generically written.
|
* simdjson/generic/ondemand/*.h: individual On-Demand classes, generically written.
|
||||||
* simdjson/generic/ondemand/dependencies.h: dependencies on common, non-implementation-specific simdjson classes. This will be included before including amalgamated.h.
|
* simdjson/generic/ondemand/dependencies.h: dependencies on common, non-implementation-specific simdjson classes. This will be included before including amalgamated.h.
|
||||||
* simdjson/generic/ondemand/amalgamated.h: all generic ondemand classes for an implementation.
|
* simdjson/generic/ondemand/amalgamated.h: all generic ondemand classes for an implementation.
|
||||||
|
* simdjson/builder.h: the `simdjson::builder` namespace. Includes all public builder classes.
|
||||||
|
* simdjson/builtin/builder.h: the `simdjson::builtin::builder` namespace.
|
||||||
|
* simdjson/arm64|fallback|haswell|icelake|ppc64|westmere/builder.h: the `simdjson::<implementation>::builder` namespace. Builder compiled for the specific implementation.
|
||||||
|
* simdjson/generic/builder/*.h: individual Builder classes, generically written.
|
||||||
|
* simdjson/generic/builder/dependencies.h: dependencies on common, non-implementation-specific simdjson classes. This will be included before including amalgamated.h.
|
||||||
|
* simdjson/generic/builder/amalgamated.h: all generic builder classes for an implementation.
|
||||||
* **src:** The source files for non-inlined functionality (e.g. the architecture-specific parser
|
* **src:** The source files for non-inlined functionality (e.g. the architecture-specific parser
|
||||||
implementations).
|
implementations).
|
||||||
* simdjson.cpp: A "main source" that includes all implementation files from src/. This is
|
* simdjson.cpp: A "main source" that includes all implementation files from src/. This is
|
||||||
@@ -147,6 +171,7 @@ Other important files and directories:
|
|||||||
* **.github/workflows:** Definitions for GitHub Actions (CI).
|
* **.github/workflows:** Definitions for GitHub Actions (CI).
|
||||||
* **singleheader:** Contains generated `simdjson.h` and `simdjson.cpp` that we release. The files `singleheader/simdjson.h` and `singleheader/simdjson.cpp` should never be edited by hand.
|
* **singleheader:** Contains generated `simdjson.h` and `simdjson.cpp` that we release. The files `singleheader/simdjson.h` and `singleheader/simdjson.cpp` should never be edited by hand.
|
||||||
* **singleheader/amalgamate.py:** Generates `singleheader/simdjson.h` and `singleheader/simdjson.cpp` for release (python script). If you add a new implementation (e.g., rvv), you need to edit this file (IMPLEMENTATIONS).
|
* **singleheader/amalgamate.py:** Generates `singleheader/simdjson.h` and `singleheader/simdjson.cpp` for release (python script). If you add a new implementation (e.g., rvv), you need to edit this file (IMPLEMENTATIONS).
|
||||||
|
* **singleheader/amalgation_helper.py:** Generates and `amalgamation_report.html` that helps you understand the status of each file.
|
||||||
* **benchmark:** This is where we do benchmarking. Benchmarking is core to every change we make; the
|
* **benchmark:** This is where we do benchmarking. Benchmarking is core to every change we make; the
|
||||||
cardinal rule is don't regress performance without knowing exactly why, and what you're trading
|
cardinal rule is don't regress performance without knowing exactly why, and what you're trading
|
||||||
for it. Many of our benchmarks are microbenchmarks. We are effectively doing controlled scientific experiments for the purpose of understanding what affects our performance. So we simplify as much as possible. We try to avoid irrelevant factors such as page faults, interrupts, unnecessary system calls. We recommend checking the performance as follows:
|
for it. Many of our benchmarks are microbenchmarks. We are effectively doing controlled scientific experiments for the purpose of understanding what affects our performance. So we simplify as much as possible. We try to avoid irrelevant factors such as page faults, interrupts, unnecessary system calls. We recommend checking the performance as follows:
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
simdjson : Parsing gigabytes of JSON per second
|
simdjson : Parsing gigabytes of JSON per second
|
||||||
===============================================
|
===============================================
|
||||||
|
|
||||||
<img src="images/logo.png" width="10%" style="float: right">
|
<img src="images/official_logo/logo_noir/SVG/logo_simdjson_noir.svg" width="40%" style="float: right">
|
||||||
|
|
||||||
JSON is everywhere on the Internet. Servers spend a *lot* of time parsing it. We need a fresh
|
JSON is everywhere on the Internet. Servers spend a *lot* of time parsing it. We need a fresh
|
||||||
approach. The simdjson library uses commonly available SIMD instructions and microparallel algorithms
|
approach. The simdjson library uses commonly available SIMD instructions and microparallel algorithms
|
||||||
to parse JSON 4x faster than RapidJSON and 25x faster than JSON for Modern C++.
|
to parse JSON 4x faster than RapidJSON and 25x faster than JSON for Modern C++.
|
||||||
@@ -116,6 +117,8 @@ Usage documentation is available:
|
|||||||
* [Implementation Selection](doc/implementation-selection.md) describes runtime CPU detection and
|
* [Implementation Selection](doc/implementation-selection.md) describes runtime CPU detection and
|
||||||
how you can work with it.
|
how you can work with it.
|
||||||
* [API](https://simdjson.github.io/simdjson/) contains the automatically generated API documentation.
|
* [API](https://simdjson.github.io/simdjson/) contains the automatically generated API documentation.
|
||||||
|
* [Compile-Time Parsing](doc/compile_time.md) presents our compile-time parsing function (C++26 only).
|
||||||
|
|
||||||
|
|
||||||
Godbolt
|
Godbolt
|
||||||
-------------
|
-------------
|
||||||
@@ -210,6 +213,21 @@ For the video inclined, <br />
|
|||||||
[](http://www.youtube.com/watch?v=wlvKAT7SZIQ)<br />
|
[](http://www.youtube.com/watch?v=wlvKAT7SZIQ)<br />
|
||||||
(It was the best voted talk, we're kinda proud of it.)
|
(It was the best voted talk, we're kinda proud of it.)
|
||||||
|
|
||||||
|
Citing this work
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
If you use simdjson in published research, please cite the software library. A suitable BibTeX entry is:
|
||||||
|
|
||||||
|
```bibtex
|
||||||
|
@misc{simdjson,
|
||||||
|
title={{The simdjson library: Parsing Gigabytes of JSON per Second}},
|
||||||
|
author={Daniel Lemire and Geoff Langdale and John Keiser and Paul Dreik and Francisco Thiesen and others},
|
||||||
|
year={2019},
|
||||||
|
howpublished={Software library},
|
||||||
|
note={https://github.com/simdjson/simdjson}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Funding
|
Funding
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ static u32 (*kpc_get_counter_count)(u32 classes);
|
|||||||
|
|
||||||
/// Get counter accumulations.
|
/// Get counter accumulations.
|
||||||
/// If `all_cpus` is true, the buffer count should not smaller than
|
/// If `all_cpus` is true, the buffer count should not smaller than
|
||||||
/// (cpu_count * counter_count). Otherwize, the buffer count should not smaller
|
/// (cpu_count * counter_count). Otherwise, the buffer count should not smaller
|
||||||
/// than (counter_count).
|
/// than (counter_count).
|
||||||
/// @see kpc_get_counter_count(), kpc_cpu_count().
|
/// @see kpc_get_counter_count(), kpc_cpu_count().
|
||||||
/// @param all_cpus true for all CPUs, false for current cpu.
|
/// @param all_cpus true for all CPUs, false for current cpu.
|
||||||
@@ -374,7 +374,7 @@ static int kperf_lightweight_pet_set(u32 enabled) {
|
|||||||
// These functions do not require root privileges.
|
// These functions do not require root privileges.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
// KPEP CPU archtecture constants.
|
// KPEP CPU architecture constants.
|
||||||
#define KPEP_ARCH_I386 0
|
#define KPEP_ARCH_I386 0
|
||||||
#define KPEP_ARCH_X86_64 1
|
#define KPEP_ARCH_X86_64 1
|
||||||
#define KPEP_ARCH_ARM 2
|
#define KPEP_ARCH_ARM 2
|
||||||
@@ -414,7 +414,7 @@ typedef struct kpep_db {
|
|||||||
usize fixed_counter_count;
|
usize fixed_counter_count;
|
||||||
usize config_counter_count;
|
usize config_counter_count;
|
||||||
usize power_counter_count;
|
usize power_counter_count;
|
||||||
u32 archtecture; ///< see `KPEP CPU archtecture constants` above.
|
u32 architecture; ///< see `KPEP CPU architecture constants` above.
|
||||||
u32 fixed_counter_bits;
|
u32 fixed_counter_bits;
|
||||||
u32 config_counter_bits;
|
u32 config_counter_bits;
|
||||||
u32 power_counter_bits;
|
u32 power_counter_bits;
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ editing CMAKE_CXX_FLAGS")
|
|||||||
# /EHc used in conjection with /EHs indicates that extern "C" functions
|
# /EHc used in conjection with /EHs indicates that extern "C" functions
|
||||||
# never throw (terminate-on-throw)
|
# never throw (terminate-on-throw)
|
||||||
# Here, we disable both with the - argument negation operator
|
# Here, we disable both with the - argument negation operator
|
||||||
string(REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
if(CMAKE_CXX_FLAGS)
|
||||||
|
string(REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
||||||
|
endif()
|
||||||
# Because we cannot change the flag above on an individual target (yet), the
|
# Because we cannot change the flag above on an individual target (yet), the
|
||||||
# definition below must similarly be added globally
|
# definition below must similarly be added globally
|
||||||
add_definitions(-D_HAS_EXCEPTIONS=0)
|
add_definitions(-D_HAS_EXCEPTIONS=0)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
The Basics
|
The Basics
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
|
||||||
An overview of what you need to know to use simdjson to parse JSON documents, with examples.
|
An overview of what you need to know to use simdjson to parse JSON documents, with examples.
|
||||||
[Our documentation regarding the generation (serialization) of JSON documents is in a
|
[Our documentation regarding the generation (serialization) of JSON documents is in a
|
||||||
separate document](https://github.com/simdjson/simdjson/blob/master/doc/builder.md).
|
separate document](https://github.com/simdjson/simdjson/blob/master/doc/builder.md).
|
||||||
@@ -21,6 +22,7 @@ separate document](https://github.com/simdjson/simdjson/blob/master/doc/builder.
|
|||||||
* [1. Specialize `simdjson::ondemand::value::get` to get custom types (pre-C++20)](#1-specialize-simdjsonondemandvalueget-to-get-custom-types-pre-c20)
|
* [1. Specialize `simdjson::ondemand::value::get` to get custom types (pre-C++20)](#1-specialize-simdjsonondemandvalueget-to-get-custom-types-pre-c20)
|
||||||
* [2. Use `tag_invoke` for custom types (C++20)](#2-use-tag_invoke-for-custom-types-c20)
|
* [2. Use `tag_invoke` for custom types (C++20)](#2-use-tag_invoke-for-custom-types-c20)
|
||||||
* [3. Using static reflection (C++26)](#3-using-static-reflection-c26)
|
* [3. Using static reflection (C++26)](#3-using-static-reflection-c26)
|
||||||
|
+ [Special cases](#special-cases)
|
||||||
* [The simdjson::from shortcut (experimental, C++20)](#the-simdjsonfrom-shortcut-experimental-c20)
|
* [The simdjson::from shortcut (experimental, C++20)](#the-simdjsonfrom-shortcut-experimental-c20)
|
||||||
- [Minifying JSON strings without parsing](#minifying-json-strings-without-parsing)
|
- [Minifying JSON strings without parsing](#minifying-json-strings-without-parsing)
|
||||||
- [UTF-8 validation (alone)](#utf-8-validation-alone)
|
- [UTF-8 validation (alone)](#utf-8-validation-alone)
|
||||||
@@ -167,8 +169,10 @@ For efficiency reasons, simdjson requires a string with a few bytes (`simdjson::
|
|||||||
at the end, these bytes may be read but their content does not affect the parsing. In practice,
|
at the end, these bytes may be read but their content does not affect the parsing. In practice,
|
||||||
it means that the JSON inputs should be stored in a memory region with `simdjson::SIMDJSON_PADDING`
|
it means that the JSON inputs should be stored in a memory region with `simdjson::SIMDJSON_PADDING`
|
||||||
extra bytes at the end. You do not have to set these bytes to specific values though you may
|
extra bytes at the end. You do not have to set these bytes to specific values though you may
|
||||||
want to if you want to avoid runtime warnings with some sanitizers. Advanced users may want to
|
want to if you want to avoid runtime warnings with some sanitizers. We expect the user
|
||||||
read the section Free Padding in [our performance notes](performance.md).
|
of the library to load the data (from disk or from the network) into a padded buffer. To make
|
||||||
|
this easy, we provide the `padded_string::load` function which loads files from disk in a padded buffer.
|
||||||
|
[You can similarly fetch a file from a URL to a padded string](https://github.com/simdjson/curltostring) using our `simdjson::padded_string_builder`. Advanced users may want to read the section Free Padding in [our performance notes](performance.md).
|
||||||
|
|
||||||
The simdjson library offers a tree-like [API](https://en.wikipedia.org/wiki/API), which you can
|
The simdjson library offers a tree-like [API](https://en.wikipedia.org/wiki/API), which you can
|
||||||
access by creating a `ondemand::parser` and calling the `iterate()` method. The iterate method
|
access by creating a `ondemand::parser` and calling the `iterate()` method. The iterate method
|
||||||
@@ -181,6 +185,9 @@ auto json = padded_string::load("twitter.json"); // load JSON file 'twitter.json
|
|||||||
ondemand::document doc = parser.iterate(json); // position a pointer at the beginning of the JSON data
|
ondemand::document doc = parser.iterate(json); // position a pointer at the beginning of the JSON data
|
||||||
```
|
```
|
||||||
|
|
||||||
|
(Windows users compiling with C++17 or better may use `wchar_t` strings to support non-ASCII
|
||||||
|
filenames: `padded_string::load(L"twitter.json")`.)
|
||||||
|
|
||||||
If you prefer not to create your own `ondemand::parser` instance, you can access
|
If you prefer not to create your own `ondemand::parser` instance, you can access
|
||||||
a thread-local version by calling `ondemand::parser.get_parser()`.
|
a thread-local version by calling `ondemand::parser.get_parser()`.
|
||||||
|
|
||||||
@@ -349,7 +356,13 @@ the macro `SIMDJSON_DEVELOPMENT_CHECKS` to 1 prior to including
|
|||||||
the `simdjson.h` header to enable these additional checks: just make sure you remove the
|
the `simdjson.h` header to enable these additional checks: just make sure you remove the
|
||||||
definition once your code has been tested. When `SIMDJSON_DEVELOPMENT_CHECKS` is set to 1, the
|
definition once your code has been tested. When `SIMDJSON_DEVELOPMENT_CHECKS` is set to 1, the
|
||||||
simdjson library runs additional (expensive) tests on your code to help ensure that you are
|
simdjson library runs additional (expensive) tests on your code to help ensure that you are
|
||||||
using the library in a safe manner.
|
using the library in a safe manner. We add asserts which may halt your program, helping
|
||||||
|
you find the bad programming pattern.
|
||||||
|
|
||||||
|
When `SIMDJSON_DEVELOPMENT_CHECKS`, some of our data structures contain extra data for
|
||||||
|
tracking explicitly potential programming mistakes. Thus you should not relying on the
|
||||||
|
size (`sizeof`) of our data structures to be constant: they may change depending on the
|
||||||
|
compiler settings.
|
||||||
|
|
||||||
Once your code has been tested, you can then run it in
|
Once your code has been tested, you can then run it in
|
||||||
Release mode: under Visual Studio, it means having the `_DEBUG` macro undefined, and, for other
|
Release mode: under Visual Studio, it means having the `_DEBUG` macro undefined, and, for other
|
||||||
@@ -432,8 +445,8 @@ support for users who avoid exceptions. See [the simdjson error handling documen
|
|||||||
|
|
||||||
If you know the type of the value, you can cast it right there, too! `for (double value : array) { ... }`.
|
If you know the type of the value, you can cast it right there, too! `for (double value : array) { ... }`.
|
||||||
|
|
||||||
You may also use explicit iterators: `for(auto i = array.begin(); i != array.end(); i++) {}`. You can check that an array is empty with the condition `auto i = array.begin(); if (i == array.end()) {...}`.
|
You may also use explicit iterators: `for(auto i = array.begin(); i != array.end(); i++) {}`. You can check that an array is empty with the condition `auto i = array.begin(); if (i == array.end()) {...}`. You should derefence (`*i`) an iterator at most once before incrementing it (`i++`), when compiling in debug mode with development checks, we add asserts to help you identify such a mistake.
|
||||||
* **Object Iteration:** You can iterate through an object's fields, as well: `for (auto field : object) { ... }`. You may also use explicit iterators : `for(auto i = object.begin(); i != object.end(); i++) { auto field = *i; .... }`. You can check that an object is empty with the condition `auto i = object.begin(); if (i == object.end()) {...}`.
|
* **Object Iteration:** You can iterate through an object's fields, as well: `for (auto field : object) { ... }`.
|
||||||
- `field.unescaped_key()` will get you the unescaped key string as a `std::string_view` instance. E.g., the JSON string `"\u00e1"` becomes the Unicode string `á`. Optionally, you pass `true` as a parameter to the `unescaped_key` method if you want invalid escape sequences to be replaced by a default replacement character (e.g., `\ud800\ud801\ud811`): otherwise bad escape sequences lead to an immediate error.
|
- `field.unescaped_key()` will get you the unescaped key string as a `std::string_view` instance. E.g., the JSON string `"\u00e1"` becomes the Unicode string `á`. Optionally, you pass `true` as a parameter to the `unescaped_key` method if you want invalid escape sequences to be replaced by a default replacement character (e.g., `\ud800\ud801\ud811`): otherwise bad escape sequences lead to an immediate error.
|
||||||
- `field.escaped_key()` will get you the key string as as a `std::string_view` instance, but unlike `unescaped_key()`, the key is not processed, so no unescaping is done. E.g., the JSON string `"\u00e1"` becomes the Unicode string `\u00e1`. We expect that `escaped_key()` is faster than `field.unescaped_key()`.
|
- `field.escaped_key()` will get you the key string as as a `std::string_view` instance, but unlike `unescaped_key()`, the key is not processed, so no unescaping is done. E.g., the JSON string `"\u00e1"` becomes the Unicode string `\u00e1`. We expect that `escaped_key()` is faster than `field.unescaped_key()`.
|
||||||
- `field.value()` will get you the value, which you can then use all these other methods on.
|
- `field.value()` will get you the value, which you can then use all these other methods on.
|
||||||
@@ -446,8 +459,12 @@ support for users who avoid exceptions. See [the simdjson error handling documen
|
|||||||
|
|
||||||
When you are iterating through an object, you are advancing through its keys and values. You should not also access the object or other objects. E.g. within a loop over `myobject`, you should not be accessing `myobject`. The following is an anti-pattern: `for(auto value: myobject) {myobject["mykey"]}`.
|
When you are iterating through an object, you are advancing through its keys and values. You should not also access the object or other objects. E.g. within a loop over `myobject`, you should not be accessing `myobject`. The following is an anti-pattern: `for(auto value: myobject) {myobject["mykey"]}`.
|
||||||
|
|
||||||
|
We discourage using the object iterators explicitly: `for(auto i = object.begin(); i != object.end(); i++) { auto field = *i; .... }`. In addition to the usual requirement to check against `end()` prior to dereferencing, you must also always dereference the pointer (`*it`) exactly once before you increment it (`it++`). You must also only deference the iterator once (never more than once). When compiling in
|
||||||
|
debug mode with development checks, we add asserts to help check whether you correctly
|
||||||
|
dereferenced the pointer before incrementing it.
|
||||||
|
|
||||||
You should never reset an object as you are iterating through it. The following is an anti-pattern: `for(auto value: myobject) {myobject.reset()}`.
|
You should never reset an object as you are iterating through it. The following is an anti-pattern: `for(auto value: myobject) {myobject.reset()}`.
|
||||||
* **Array Index:** Because it is forward-only, you cannot look up an array element by index by index. Instead,
|
* **Array Index:** Because it is forward-only, you cannot look up an array element by index. Instead,
|
||||||
you should iterate through the array and keep an index yourself. Exceptionally, if need a single value
|
you should iterate through the array and keep an index yourself. Exceptionally, if need a single value
|
||||||
out of the array, you may use an array access (e.g., `array[1]`). You should never reset an array as you are iterating through it. The following is an anti-pattern: `for(auto value: myarray) {myarray.reset()}`.
|
out of the array, you may use an array access (e.g., `array[1]`). You should never reset an array as you are iterating through it. The following is an anti-pattern: `for(auto value: myarray) {myarray.reset()}`.
|
||||||
* **Field Access:** To get the value of the "foo" field in an object, use `object["foo"]`. This will
|
* **Field Access:** To get the value of the "foo" field in an object, use `object["foo"]`. This will
|
||||||
@@ -476,7 +493,7 @@ support for users who avoid exceptions. See [the simdjson error handling documen
|
|||||||
> unlike `key()`, it has to determine the location of the final quote character.
|
> unlike `key()`, it has to determine the location of the final quote character.
|
||||||
>
|
>
|
||||||
> ```cpp
|
> ```cpp
|
||||||
> auto json = R"({"k\u0065y": 1})"_padded;
|
> auto json = R"({"k\u0065y": 1})"_padded; // R"( ... )" is a C++ raw string literal.
|
||||||
> ondemand::parser parser;
|
> ondemand::parser parser;
|
||||||
> auto doc = parser.iterate(json);
|
> auto doc = parser.iterate(json);
|
||||||
> ondemand::object object = doc.get_object();
|
> ondemand::object object = doc.get_object();
|
||||||
@@ -501,7 +518,7 @@ support for users who avoid exceptions. See [the simdjson error handling documen
|
|||||||
>
|
>
|
||||||
> ```cpp
|
> ```cpp
|
||||||
> ondemand::parser parser;
|
> ondemand::parser parser;
|
||||||
> auto json = R"( { "x": 1, "y": 2 } )"_padded;
|
> auto json = R"( { "x": 1, "y": 2 } )"_padded; // R"( ... )" is a C++ raw string literal.
|
||||||
> auto doc = parser.iterate(json);
|
> auto doc = parser.iterate(json);
|
||||||
> double y = doc.find_field("y"); // The cursor is now after the 2 (at })
|
> double y = doc.find_field("y"); // The cursor is now after the 2 (at })
|
||||||
> double x = doc.find_field("x"); // This fails, because there are no more fields after "y"
|
> double x = doc.find_field("x"); // This fails, because there are no more fields after "y"
|
||||||
@@ -522,13 +539,13 @@ support for users who avoid exceptions. See [the simdjson error handling documen
|
|||||||
> auto silly_json = R"( { "test": "result" } )"_padded;
|
> auto silly_json = R"( { "test": "result" } )"_padded;
|
||||||
> ondemand::document doc = parser.iterate(silly_json);
|
> ondemand::document doc = parser.iterate(silly_json);
|
||||||
> std::cout << simdjson::to_json_string(doc["test"]) << std::endl; // Requires simdjson 1.0 or better
|
> std::cout << simdjson::to_json_string(doc["test"]) << std::endl; // Requires simdjson 1.0 or better
|
||||||
>````
|
> ```
|
||||||
> ```cpp
|
> ```cpp
|
||||||
> // retrieves an unescaped string value as a string_view instance
|
> // retrieves an unescaped string value as a string_view instance
|
||||||
> auto silly_json = R"( { "test": "result" } )"_padded;
|
> auto silly_json = R"( { "test": "result" } )"_padded;
|
||||||
> ondemand::document doc = parser.iterate(silly_json);
|
> ondemand::document doc = parser.iterate(silly_json);
|
||||||
> std::cout << std::string_view(doc["test"]) << std::endl;
|
> std::cout << std::string_view(doc["test"]) << std::endl;
|
||||||
>````
|
> ```
|
||||||
You can use `to_json_string` to efficiently extract components of a JSON document to reconstruct a new JSON document, as in the following example:
|
You can use `to_json_string` to efficiently extract components of a JSON document to reconstruct a new JSON document, as in the following example:
|
||||||
> ```cpp
|
> ```cpp
|
||||||
> auto cars_json = R"( [
|
> auto cars_json = R"( [
|
||||||
@@ -557,7 +574,7 @@ support for users who avoid exceptions. See [the simdjson error handling documen
|
|||||||
> oss << "]";
|
> oss << "]";
|
||||||
> auto json_string = oss.str();
|
> auto json_string = oss.str();
|
||||||
> // json_string == "[[ 40.1, 39.9, 37.7, 40.4 ],[ 30.1, 31.0, 28.6, 28.7 ]]"
|
> // json_string == "[[ 40.1, 39.9, 37.7, 40.4 ],[ 30.1, 31.0, 28.6, 28.7 ]]"
|
||||||
>````
|
> ```
|
||||||
* **Extracting Values (without exceptions):** You can use a variant usage of `get()` with error
|
* **Extracting Values (without exceptions):** You can use a variant usage of `get()` with error
|
||||||
codes to avoid exceptions. You first declare the variable of the appropriate type (`double`,
|
codes to avoid exceptions. You first declare the variable of the appropriate type (`double`,
|
||||||
`uint64_t`, `int64_t`, `bool`, `ondemand::object` and `ondemand::array`) and pass it by reference
|
`uint64_t`, `int64_t`, `bool`, `ondemand::object` and `ondemand::array`) and pass it by reference
|
||||||
@@ -1754,57 +1771,71 @@ int64_t x = obj.at_path("$.c.foo.a[1]"); // 20
|
|||||||
x = obj.at_path("$.d.foo2.a.2"); // 30
|
x = obj.at_path("$.d.foo2.a.2"); // 30
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Using `at_path_with_wildcard` for JSONPath Queries (On-Demand)
|
||||||
|
|
||||||
|
The `at_path_with_wildcard` function in simdjson extends the JSONPath querying capabilities by supporting wildcard expressions (`*`) in JSON paths. This allows users to retrieve multiple elements from a JSON document in a single query. For example, you can use `$.address.*` to fetch all fields within the `address` object or `$.phoneNumbers[*].numbers[*]` to retrieve all phone numbers across multiple objects in an array.
|
||||||
|
|
||||||
### C++26
|
The `*` wildcard matches all elements at a specific level. For instance, `$.address.*` retrieves all key-value pairs in the `address` object, while `$.*.streetAddress` fetches all `streetAddress` fields across objects at the root level. You can combine wildcards with array indexing. For example, `$.phoneNumbers[*].numbers[1]` retrieves the second number from each `numbers` array in the `phoneNumbers` array. If no elements match the wildcard query, the function returns an empty result. For instance, querying `$.empty_object.*` or `$.empty_array.*` will yield an empty set.
|
||||||
|
|
||||||
|
### Example Usage
|
||||||
|
|
||||||
We also support shit
|
Here is an example demonstrating the use of `at_path_with_wildcard`:
|
||||||
If you have C++26 support with reflection, and you have set the `SIMDJSON_STATIC_REFLECTION` macro, e
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
#define SIMDJSON_STATIC_REFLECTION 1
|
simdjson::padded_string json_string = R"(
|
||||||
//...
|
{
|
||||||
#include "simdjson.h"
|
"firstName": "John",
|
||||||
```
|
"lastName": "doe",
|
||||||
|
"age": 26,
|
||||||
|
"address": {
|
||||||
|
"streetAddress": "naist street",
|
||||||
|
"city": "Nara",
|
||||||
|
"postalCode": "630-0192"
|
||||||
|
},
|
||||||
|
"phoneNumbers": [
|
||||||
|
{
|
||||||
|
"type": "iPhone",
|
||||||
|
"numbers": ["0123-4567-8888", "0123-4567-8788"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "home",
|
||||||
|
"numbers": ["0123-4567-8910"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})"_padded;
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto cars_json = R"( [
|
|
||||||
{ "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
|
|
||||||
{ "make": "Kia", "model": "Soul", "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
|
|
||||||
{ "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
|
|
||||||
] )"_padded;
|
|
||||||
ondemand::parser parser;
|
ondemand::parser parser;
|
||||||
auto cars = parser.iterate(cars_json);
|
ondemand::document doc = parser.iterate(json_string);
|
||||||
cout << cars.at_path("[0].tire_pressure[1]") << endl; // Prints 39.9
|
|
||||||
|
// Fetch all fields in the address object
|
||||||
|
std::vector<ondemand::value> values;
|
||||||
|
auto error = doc.at_path_with_wildcard("$.address.*").get(values);
|
||||||
|
if (!error) {
|
||||||
|
for (auto value : values) {
|
||||||
|
std::string_view field;
|
||||||
|
if (value.get(field) == SUCCESS) {
|
||||||
|
std::cout << field << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all phone numbers
|
||||||
|
error = doc.at_path_with_wildcard("$.phoneNumbers[*].numbers[*]").get(values);
|
||||||
|
if (!error) {
|
||||||
|
for (auto value : values) {
|
||||||
|
std::string_view number;
|
||||||
|
if (value.get(number) == SUCCESS) {
|
||||||
|
std::cout << number << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### C++26
|
This function is particularly useful for extracting data from complex JSON structures with nested arrays and objects. By leveraging wildcards, you can simplify your queries and reduce the need for multiple iterations.
|
||||||
|
|
||||||
|
|
||||||
We also support shit
|
|
||||||
If you have C++26 support with reflection, and you have set the `SIMDJSON_STATIC_REFLECTION` macro, e
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#define SIMDJSON_STATIC_REFLECTION 1
|
|
||||||
//...
|
|
||||||
#include "simdjson.h"
|
|
||||||
```
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto cars_json = R"( [
|
|
||||||
{ "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
|
|
||||||
{ "make": "Kia", "model": "Soul", "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
|
|
||||||
{ "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
|
|
||||||
] )"_padded;
|
|
||||||
ondemand::parser parser;
|
|
||||||
auto cars = parser.iterate(cars_json);
|
|
||||||
cout << cars.at_path("[0].tire_pressure[1]") << endl; // Prints 39.9
|
|
||||||
```
|
|
||||||
|
|
||||||
## Compile-Time JSONPath and JSON Pointer (C++26 Reflection)
|
## Compile-Time JSONPath and JSON Pointer (C++26 Reflection)
|
||||||
|
|
||||||
simdjson provides **compile-time validated** JSONPath and JSON Pointer accessors when using C++26 Static Reflection. These accessors validate paths against struct definitions at compile time and generate optimized code with zero runtime overhead. In some cases, we find that it is much faster. Furthermore, it is safer in the sense that the expression
|
The simdjson library provides **compile-time validated** JSONPath and JSON Pointer accessors when using C++26 Static Reflection. These accessors validate paths against struct definitions at compile time and generate optimized code with zero runtime overhead. In some cases, we find that it is much faster. Furthermore, it is safer in the sense that the expression
|
||||||
is validated at compile-time.
|
is validated at compile-time.
|
||||||
|
|
||||||
**Requirements:** C++26 compiler with P2996 reflection support and `-DSIMDJSON_STATIC_REFLECTION=ON` build flag.
|
**Requirements:** C++26 compiler with P2996 reflection support and `-DSIMDJSON_STATIC_REFLECTION=ON` build flag.
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ speed and high convenience.
|
|||||||
* [C++26 static reflection](#c--26-static-reflection)
|
* [C++26 static reflection](#c--26-static-reflection)
|
||||||
+ [Without `string_buffer` instance](#without--string-buffer--instance)
|
+ [Without `string_buffer` instance](#without--string-buffer--instance)
|
||||||
+ [Without `string_buffer` instance but with explicit error handling](#without--string-buffer--instance-but-with-explicit-error-handling)
|
+ [Without `string_buffer` instance but with explicit error handling](#without--string-buffer--instance-but-with-explicit-error-handling)
|
||||||
|
+ [Pretty formatted (fractured JSON)](#pretty-formatted-fractured-json)
|
||||||
|
|
||||||
Overview: string_builder
|
Overview: string_builder
|
||||||
---------------------------
|
---------------------------
|
||||||
@@ -332,7 +333,7 @@ pattern:
|
|||||||
|
|
||||||
### Customization
|
### Customization
|
||||||
|
|
||||||
If you want to serialize a value in a custome way, you can do it with a
|
If you want to serialize a value in a custom way, you can do it with a
|
||||||
`tag_invoke` specialization like the following example which will map
|
`tag_invoke` specialization like the following example which will map
|
||||||
the year attribute to a string.
|
the year attribute to a string.
|
||||||
|
|
||||||
@@ -364,3 +365,49 @@ void tag_invoke(serialize_tag, builder_type &builder, const Car& car) {
|
|||||||
|
|
||||||
} // namespace simdjson
|
} // namespace simdjson
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Pretty formatted (fractured JSON)
|
||||||
|
|
||||||
|
In some instances, you may want your JSON to be more readable. For this pupose, we also
|
||||||
|
support the Fractured JSON standard.
|
||||||
|
|
||||||
|
```Cpp
|
||||||
|
TableTestData data{
|
||||||
|
{{1, "Alice", true}, {2, "Bob", false}, {3, "Carol", true}, {4, "Dave", false}}
|
||||||
|
};
|
||||||
|
|
||||||
|
fractured_json_options opts;
|
||||||
|
opts.enable_table_format = true;
|
||||||
|
opts.min_table_rows = 3;
|
||||||
|
|
||||||
|
std::string formatted = simdjson::to_fractured_json_string(data, opts);
|
||||||
|
```
|
||||||
|
|
||||||
|
The result might be as follows.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"records": [
|
||||||
|
{ "active": true , "id": 1, "name": "Alice" },
|
||||||
|
{ "active": false, "id": 2, "name": "Bob" },
|
||||||
|
{ "active": true , "id": 3, "name": "Carol" },
|
||||||
|
{ "active": false, "id": 4, "name": "Dave" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `fractured_json_options` struct allows you to customize the formatting behavior. It includes the following options:
|
||||||
|
|
||||||
|
- `max_total_line_length` (default: 120): Maximum total characters per line. Content exceeding this will be expanded to multiple lines.
|
||||||
|
- `max_inline_length` (default: 80): Maximum length for inlined elements. Simple arrays/objects shorter than this may be rendered inline.
|
||||||
|
- `max_inline_complexity` (default: 2): Maximum nesting depth for inline rendering. Elements with complexity exceeding this will be expanded. Complexity 0 = scalar, 1 = flat array/object, 2 = one level of nesting.
|
||||||
|
- `max_compact_array_complexity` (default: 1): Maximum complexity for compact array formatting. Arrays with elements of this complexity or less may have multiple items per line.
|
||||||
|
- `indent_spaces` (default: 4): Number of spaces per indentation level.
|
||||||
|
- `enable_table_format` (default: true): Enable tabular formatting for arrays of similar objects. When enabled, arrays of objects with identical keys are formatted as aligned tables.
|
||||||
|
- `min_table_rows` (default: 3): Minimum number of rows to trigger table mode.
|
||||||
|
- `table_similarity_threshold` (default: 0.8): Similarity threshold for table detection. Objects must share at least this fraction of keys to be formatted as a table.
|
||||||
|
- `enable_compact_multiline` (default: true): Enable compact multiline arrays. When enabled, arrays of simple elements may have multiple items per line.
|
||||||
|
- `max_items_per_line` (default: 10): Maximum array items per line in compact mode.
|
||||||
|
- `simple_bracket_padding` (default: true): Add space inside brackets for simple containers. When true: `{ "key": "value" }`, when false: `{"key": "value"}`.
|
||||||
|
- `colon_padding` (default: true): Add space after colons. When true: `"key": "value"`, when false: `"key":"value"`.
|
||||||
|
- `comma_padding` (default: true): Add space after commas in inline content. When true: `[1, 2, 3]`, when false: `[1,2,3]`.
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
# Parse json at compile time
|
||||||
|
* [Introduction](#introduction)
|
||||||
|
* [Example](#example)
|
||||||
|
* [Concepts](#concepts)
|
||||||
|
* [Loading from disk](#loading-from-disk)
|
||||||
|
* [Limitations (compile-time errors)](#limitations-compile-time-errors)
|
||||||
|
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
In some instances, you may want to configure your software at compile-time with a JSON document.
|
||||||
|
Maybe you have a single code base but many different possible configurations, all resulting in
|
||||||
|
different software. For example, you might be programming robots, using the same software, but
|
||||||
|
different robot configurations.
|
||||||
|
|
||||||
|
To achieve the desired result, you have a few options. You may start the software and parser a
|
||||||
|
JSON file at runtime. Or you might convert your JSON data into C++ code that you can compile with
|
||||||
|
your software.
|
||||||
|
|
||||||
|
With C++26, there is another way: parse the JSON file along with your C++ code. In this manner,
|
||||||
|
the JSON data becomes native C++ data.
|
||||||
|
|
||||||
|
The simdjson library supports parsing JSON documents at compile time if you have C++26 support. To
|
||||||
|
activate C++26 reflection support, you can compile
|
||||||
|
your code with the `SIMDJSON_STATIC_REFLECTION` macro set:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#define SIMDJSON_STATIC_REFLECTION 1
|
||||||
|
//...
|
||||||
|
#include "simdjson.h"
|
||||||
|
```
|
||||||
|
|
||||||
|
The `simdjson::compile_time::parse_json` function parses a JSON document at **compile time** and returns a `constexpr` structure reflecting its content. We support the full range of JSON values, which are mapped to C++ types as in
|
||||||
|
the following table.
|
||||||
|
|
||||||
|
|
||||||
|
| JSON type | C++ type |
|
||||||
|
|----------------|----------------------------------|
|
||||||
|
| object | anonymous struct |
|
||||||
|
| array | `std::array<T, N>` (homogeneous) |
|
||||||
|
| string | `const char*` (UTF-8) |
|
||||||
|
| number | `int64_t`, `uint64_t`, `double` |
|
||||||
|
| `true`/`false` | `bool` |
|
||||||
|
| `null` | `std::nullptr_t` |
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Suppose you want to parse the following JSON document:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
{
|
||||||
|
"port": 8080,
|
||||||
|
"host": "localhost",
|
||||||
|
"debug": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Reminder**: In C++, `R"( )"` allows us to write multi-line strings with unescaped quotes.
|
||||||
|
|
||||||
|
|
||||||
|
You can do so, at compile-time, as follows:
|
||||||
|
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
constexpr auto cfg = R"(
|
||||||
|
|
||||||
|
{
|
||||||
|
"port": 8080,
|
||||||
|
"host": "localhost",
|
||||||
|
"debug": true
|
||||||
|
}
|
||||||
|
|
||||||
|
)"_json;
|
||||||
|
|
||||||
|
// cfg.port == 8080
|
||||||
|
// std::string_view(cfg.host) == "localhost"
|
||||||
|
// cfg.debug == true
|
||||||
|
```
|
||||||
|
|
||||||
|
You can nest objects and arrays:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
constexpr auto data = R"(
|
||||||
|
|
||||||
|
{
|
||||||
|
"servers": [
|
||||||
|
{"host": "s1", "port": 3000},
|
||||||
|
{"host": "s2", "port": 3001}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
)"_json;
|
||||||
|
|
||||||
|
|
||||||
|
// data.servers.size() == 2
|
||||||
|
// std::string_view(data.servers[0].host) == "s1"
|
||||||
|
```
|
||||||
|
|
||||||
|
Top-level arrays are allowed:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
constexpr auto arr = R"(
|
||||||
|
|
||||||
|
[1, 2, 3]
|
||||||
|
|
||||||
|
)"_json;
|
||||||
|
static_assert(arr.size() == 3);
|
||||||
|
static_assert(arr[1] == 2);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Concepts
|
||||||
|
|
||||||
|
Given that the parsed data is made of structures that depend on the JSON input, you might
|
||||||
|
want to check that it conforms to your expectation. You can do so with concepts.
|
||||||
|
|
||||||
|
Let us consider this example:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
constexpr auto config = R"(
|
||||||
|
|
||||||
|
[
|
||||||
|
{ "name": "Alice", "age": 30 },
|
||||||
|
{ "name": "Bob", "age": 25 },
|
||||||
|
{ "name": "Charlie", "age": 35 }
|
||||||
|
]
|
||||||
|
|
||||||
|
)"_json;
|
||||||
|
```
|
||||||
|
|
||||||
|
You might want to ensure that the result is an array of persons. You can define your
|
||||||
|
expectation with concepts like so:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
template <typename T>
|
||||||
|
concept person = requires(T p) {
|
||||||
|
std::string_view(p.name); // has name field convertible to string_view
|
||||||
|
p.age; // has age field
|
||||||
|
requires std::is_integral_v<decltype(p.age)>; // age is integral
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Concept to validate that a type is an array of person objects
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
concept array_of_person = requires(T arr) {
|
||||||
|
arr.size(); // has size method
|
||||||
|
arr[0]; // can access elements with []
|
||||||
|
requires person<decltype(arr[0])>; // elements satisfy person concept
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
And then a simple static assert with `decltype` is sufficient to check that the expectation is met:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
constexpr auto config = R"(
|
||||||
|
|
||||||
|
[
|
||||||
|
{ "name": "Alice", "age": 30 },
|
||||||
|
{ "name": "Bob", "age": 25 },
|
||||||
|
{ "name": "Charlie", "age": 35 }
|
||||||
|
]
|
||||||
|
|
||||||
|
)"_json;
|
||||||
|
|
||||||
|
|
||||||
|
// Validate that the array satisfies the array_of_person concept
|
||||||
|
static_assert(array_of_person<decltype(config)>);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Loading from disk
|
||||||
|
|
||||||
|
In practice, you may have a JSON file, say `json_data` that you want to parse
|
||||||
|
at compile time. You may do so as follows.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
constexpr const char json_data[] = {
|
||||||
|
#embed "test.json"
|
||||||
|
, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr auto json = simdjson::compile_time::parse_json<json_data>();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Limitations (compile-time errors)
|
||||||
|
|
||||||
|
We have a few limitations which trigger compile-time errors if violated.
|
||||||
|
|
||||||
|
|
||||||
|
- Only JSON objects and arrays are supported at the top level (no primitives).
|
||||||
|
We will lift this limitation in the future.
|
||||||
|
- Strings are represented using the `const char*` in UTF-8, but they must not
|
||||||
|
contain embedded nulls. We would prefer to represent them as std::string or
|
||||||
|
std::string_view, and hope to do so in the future.
|
||||||
|
- Heterogeneous arrays are not supported yet. E.g., you need to have arrays of
|
||||||
|
all integers, or all strings, all floats, all compatible objects, etc.
|
||||||
|
For example, the following is accepted:
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{ "name": "Alice", "age": 30 },
|
||||||
|
{ "name": "Bob", "age": 25 },
|
||||||
|
{ "name": "Charlie", "age": 35 }
|
||||||
|
]
|
||||||
|
```
|
||||||
|
but the following is not:
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{ "name": "Alice", "age": 30 },
|
||||||
|
"Just a string",
|
||||||
|
42,
|
||||||
|
{ "name": "Charlie", "age": 35 }
|
||||||
|
]
|
||||||
|
```
|
||||||
|
We may support heterogeneous arrays in the future with std::variant types.
|
||||||
|
- We parse the first JSON document encountered in the string. Trailing
|
||||||
|
characters are ignored. Thus if your JSON begins with {"a":1}, everything
|
||||||
|
after the closing brace is ignored. This limitation will be lifted in the future,
|
||||||
|
reporting an error.
|
||||||
|
|
||||||
|
These limitations are safe in the sense that they result in compile-time errors.
|
||||||
|
Thus you will not get truncated strings or imprecise floats silently.
|
||||||
|
|
||||||
|
|
||||||
|
Although we are committed to maintaining the functionality in the long run, the
|
||||||
|
`compile_time::parse_json` function is subject to change.
|
||||||
@@ -40,6 +40,7 @@ struct User {
|
|||||||
std::vector<std::string> emails;
|
std::vector<std::string> emails;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// R"( ... )" is a C++ raw string literal.
|
||||||
const padded_string json = R"({
|
const padded_string json = R"({
|
||||||
"name": "Alice",
|
"name": "Alice",
|
||||||
"age": 30,
|
"age": 30,
|
||||||
|
|||||||
@@ -54,6 +54,24 @@ dom::parser parser;
|
|||||||
dom::element doc = parser.parse("[1,2,3]"_padded); // parse a string, the _padded suffix creates a simdjson::padded_string instance
|
dom::element doc = parser.parse("[1,2,3]"_padded); // parse a string, the _padded suffix creates a simdjson::padded_string instance
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also load a `padded_string` from a file.
|
||||||
|
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto json = padded_string::load("twitter.json"); // load JSON file 'twitter.json'.
|
||||||
|
dom::element doc = parser.parse(json);
|
||||||
|
```
|
||||||
|
|
||||||
|
[You can similarly fetch a file from a URL to a padded string](https://github.com/simdjson/curltostring) using our `simdjson::padded_string_builder`.
|
||||||
|
|
||||||
|
(Windows users compiling with C++17 or better may use `wchar_t` strings to support non-ASCII
|
||||||
|
filenames: `padded_string::load(L"twitter.json")`.)
|
||||||
|
|
||||||
|
|
||||||
|
(Windows users compiling with C++17 or better may use `wchar_t` strings to support non-ASCII
|
||||||
|
filenames: `padded_string::load(L"twitter.json")`.)
|
||||||
|
|
||||||
|
|
||||||
You can copy your data directly on a `simdjson::padded_string` as follows:
|
You can copy your data directly on a `simdjson::padded_string` as follows:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -119,6 +137,7 @@ Once you have an element, you can navigate it with idiomatic C++ iterators, oper
|
|||||||
`dom::object` and `dom::array`) and pass it by reference to `get()` which gives you back an error code: e.g.,
|
`dom::object` and `dom::array`) and pass it by reference to `get()` which gives you back an error code: e.g.,
|
||||||
```cpp
|
```cpp
|
||||||
simdjson::error_code error;
|
simdjson::error_code error;
|
||||||
|
// _padded returns an simdjson::padded_string instance
|
||||||
simdjson::padded_string numberstring = "1.2"_padded; // our JSON input ("1.2")
|
simdjson::padded_string numberstring = "1.2"_padded; // our JSON input ("1.2")
|
||||||
simdjson::dom::parser parser;
|
simdjson::dom::parser parser;
|
||||||
double value; // variable where we store the value to be parsed
|
double value; // variable where we store the value to be parsed
|
||||||
@@ -153,6 +172,7 @@ Once you have an element, you can navigate it with idiomatic C++ iterators, oper
|
|||||||
The following code illustrates all of the above:
|
The following code illustrates all of the above:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
// R"( ... )" is a C++ raw string literal.
|
||||||
auto cars_json = R"( [
|
auto cars_json = R"( [
|
||||||
{ "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
|
{ "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
|
||||||
{ "make": "Kia", "model": "Soul", "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
|
{ "make": "Kia", "model": "Soul", "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
|
||||||
@@ -825,7 +845,7 @@ memcpy(padded_json_copy.get(), json, json_len);
|
|||||||
memset(padded_json_copy.get() + json_len, 0, SIMDJSON_PADDING);
|
memset(padded_json_copy.get() + json_len, 0, SIMDJSON_PADDING);
|
||||||
simdjson::dom::parser parser;
|
simdjson::dom::parser parser;
|
||||||
simdjson::dom::element element = parser.parse(padded_json_copy.get(), json_len, false);
|
simdjson::dom::element element = parser.parse(padded_json_copy.get(), json_len, false);
|
||||||
````
|
```
|
||||||
|
|
||||||
Setting the `realloc_if_needed` parameter `false` in this manner may lead to better performance since copies are avoided, but it requires that the user takes more responsibilities: the simdjson library cannot verify that the input buffer was padded with SIMDJSON_PADDING extra bytes.
|
Setting the `realloc_if_needed` parameter `false` in this manner may lead to better performance since copies are avoided, but it requires that the user takes more responsibilities: the simdjson library cannot verify that the input buffer was padded with SIMDJSON_PADDING extra bytes.
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ library provides high-speed access to files or streams containing multiple small
|
|||||||
{"text":"a"}
|
{"text":"a"}
|
||||||
{"text":"b"}
|
{"text":"b"}
|
||||||
{"text":"c"}
|
{"text":"c"}
|
||||||
...
|
"..."
|
||||||
```
|
```
|
||||||
... you want to read the entries (individual JSON documents) as quickly and as conveniently as possible. Importantly, the input might span several gigabytes, but you want to use a small (fixed) amount of memory. Ideally, you'd also like the parallelize the processing (using more than one core) to speed up the process.
|
... you want to read the entries (individual JSON documents) as quickly and as conveniently as possible. Importantly, the input might span several gigabytes, but you want to use a small (fixed) amount of memory. Ideally, you'd also like the parallelize the processing (using more than one core) to speed up the process.
|
||||||
|
|
||||||
@@ -141,7 +141,9 @@ API
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
// R"( ... )" is a C++ raw string literal.
|
||||||
auto json = R"({ "foo": 1 } { "foo": 2 } { "foo": 3 } )"_padded;
|
auto json = R"({ "foo": 1 } { "foo": 2 } { "foo": 3 } )"_padded;
|
||||||
|
// _padded returns an simdjson::padded_string instance
|
||||||
ondemand::parser parser;
|
ondemand::parser parser;
|
||||||
ondemand::document_stream docs = parser.iterate_many(json);
|
ondemand::document_stream docs = parser.iterate_many(json);
|
||||||
for (auto doc : docs) {
|
for (auto doc : docs) {
|
||||||
|
|||||||
@@ -545,7 +545,7 @@ To help visualize the algorithm, we'll walk through the example C++ given at the
|
|||||||
"statuses": [
|
"statuses": [
|
||||||
{ "id": 1, "text": "first!", "user": { "screen_name": "lemire", "name": "Daniel" }, "retweet_count": 40 },
|
{ "id": 1, "text": "first!", "user": { "screen_name": "lemire", "name": "Daniel" }, "retweet_count": 40 },
|
||||||
{ "id": 2, "text": "second!", "user": { "screen_name": "jkeiser2", "name": "John" }, "retweet_count": 3 }
|
{ "id": 2, "text": "second!", "user": { "screen_name": "jkeiser2", "name": "John" }, "retweet_count": 3 }
|
||||||
^ (depth 3 - root > statuses > tweet)
|
^ (depth 4 - root > statuses > tweet > field)
|
||||||
],
|
],
|
||||||
"search_metadata": { "count": 2 }
|
"search_metadata": { "count": 2 }
|
||||||
}
|
}
|
||||||
@@ -672,7 +672,9 @@ in production systems:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
ondemand::parser parser;
|
ondemand::parser parser;
|
||||||
|
// R"( ... )" is a C++ raw string literal.
|
||||||
const padded_string json = R"({ "parent": {"child1": {"name": "John"} , "child2": {"name": "Daniel"}} })"_padded;
|
const padded_string json = R"({ "parent": {"child1": {"name": "John"} , "child2": {"name": "Daniel"}} })"_padded;
|
||||||
|
// _padded returns an simdjson padded_string instance
|
||||||
auto doc = parser.iterate(json);
|
auto doc = parser.iterate(json);
|
||||||
ondemand::object parent = doc["parent"];
|
ondemand::object parent = doc["parent"];
|
||||||
// parent owns the focus
|
// parent owns the focus
|
||||||
|
|||||||
@@ -298,3 +298,61 @@ int main() {
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Further, whenever you allocate N bytes, memory allocators tend to allocate more memory, without you necessarily knowing about it. Under linux, you can use the `malloc_usable_size` function to see how much memory was actually allocated.
|
||||||
|
Under an Apple plateform, you can `malloc_size`. The following program illustrates the usage.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <memory>
|
||||||
|
#include <cstdlib>
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <malloc/malloc.h> // for malloc_size on macOS
|
||||||
|
#endif
|
||||||
|
#ifdef __linux__
|
||||||
|
#include <malloc.h> // for malloc_usable_size on Linux
|
||||||
|
#endif
|
||||||
|
size_t get_usable_size(void* ptr) {
|
||||||
|
#ifdef __linux__
|
||||||
|
return malloc_usable_size(ptr);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
return malloc_size(ptr);
|
||||||
|
#else
|
||||||
|
return 0; // Unsupported platform
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::cout << "Demonstrating allocation overhead and rounding with operator new\n\n";
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
std::cout << "Platform: Linux\n";
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
std::cout << "Platform: macOS (using malloc_size)\n";
|
||||||
|
#else
|
||||||
|
std::cout << "Platform: Other/unsupported (usable size will show 0)\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::cout << "Requested size | Actual usable size\n";
|
||||||
|
std::cout << "---------------|-------------------\n";
|
||||||
|
size_t total_requested = 0;
|
||||||
|
size_t total_usable = 0;
|
||||||
|
for (size_t requested = 1; requested <= 4096; requested++) {
|
||||||
|
total_requested += requested;
|
||||||
|
std::unique_ptr<char[]> ptr(new char[requested]); // Allocate
|
||||||
|
size_t usable = get_usable_size(ptr.get()); // Get usable size
|
||||||
|
total_usable += usable;
|
||||||
|
|
||||||
|
std::cout << requested << "\t | " << usable << "\n";
|
||||||
|
}
|
||||||
|
std::cout << "---------------|-------------------\n";
|
||||||
|
std::cout << "Total requested: " << total_requested << " bytes\n";
|
||||||
|
std::cout << "Total usable: " << total_usable << " bytes\n";
|
||||||
|
std::cout << "Total overhead: " << (total_usable - total_requested) << " bytes\n";
|
||||||
|
std::cout << "Percentage overhead: "
|
||||||
|
<< ((total_usable - total_requested) * 100.0 / total_requested) << " %\n";
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -8,16 +8,11 @@
|
|||||||
* Minifies by first parsing, then minifying.
|
* Minifies by first parsing, then minifying.
|
||||||
*/
|
*/
|
||||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||||
|
simdjson::padded_string str(reinterpret_cast<const char *>(Data), Size);
|
||||||
auto begin = as_chars(Data);
|
|
||||||
auto end = begin + Size;
|
|
||||||
|
|
||||||
std::string str(begin, end);
|
|
||||||
simdjson::dom::parser parser;
|
simdjson::dom::parser parser;
|
||||||
simdjson::dom::element elem;
|
simdjson::dom::element elem;
|
||||||
auto error = parser.parse(str).get(elem);
|
auto error = parser.parse(str).get(elem);
|
||||||
if (error) { return 0; }
|
if (error) { return 0; }
|
||||||
|
|
||||||
std::string minified = simdjson::minify(elem);
|
std::string minified = simdjson::minify(elem);
|
||||||
(void)minified;
|
(void)minified;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ cmake .. \
|
|||||||
-DSIMDJSON_DISABLE_DEPRECATED_API=On \
|
-DSIMDJSON_DISABLE_DEPRECATED_API=On \
|
||||||
-DSIMDJSON_FUZZ_LDFLAGS=$LIB_FUZZING_ENGINE
|
-DSIMDJSON_FUZZ_LDFLAGS=$LIB_FUZZING_ENGINE
|
||||||
|
|
||||||
cmake --build . --target all_fuzzers
|
cmake --build . --target all_fuzzers all_tests
|
||||||
|
|
||||||
cp fuzz/fuzz_* $OUT
|
cp fuzz/fuzz_* $OUT
|
||||||
|
|
||||||
|
|||||||
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 35 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 226 KiB |
|
After Width: | Height: | Size: 136 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 256 KiB |
|
After Width: | Height: | Size: 136 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 109 KiB |
|
After Width: | Height: | Size: 258 KiB |
|
After Width: | Height: | Size: 136 KiB |
@@ -52,7 +52,13 @@
|
|||||||
#include "simdjson/padded_string_view-inl.h"
|
#include "simdjson/padded_string_view-inl.h"
|
||||||
|
|
||||||
#include "simdjson/dom.h"
|
#include "simdjson/dom.h"
|
||||||
|
#include "simdjson/builder.h"
|
||||||
#include "simdjson/ondemand.h"
|
#include "simdjson/ondemand.h"
|
||||||
#include "simdjson/convert.h"
|
#include "simdjson/convert.h"
|
||||||
#include "simdjson/convert-inl.h"
|
#include "simdjson/convert-inl.h"
|
||||||
|
|
||||||
|
// Compile-time JSON parsing (C++26 P2996 reflection)
|
||||||
|
#include "simdjson/compile_time_json.h"
|
||||||
|
#include "simdjson/compile_time_json-inl.h"
|
||||||
|
|
||||||
#endif // SIMDJSON_H
|
#endif // SIMDJSON_H
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef SIMDJSON_ARM64_BUILDER_H
|
||||||
|
#define SIMDJSON_ARM64_BUILDER_H
|
||||||
|
|
||||||
|
#include "simdjson/arm64/begin.h"
|
||||||
|
#include "simdjson/generic/builder/amalgamated.h"
|
||||||
|
#include "simdjson/arm64/end.h"
|
||||||
|
|
||||||
|
#endif // SIMDJSON_ARM64_BUILDER_H
|
||||||
@@ -17,6 +17,7 @@ using namespace simd;
|
|||||||
struct backslash_and_quote {
|
struct backslash_and_quote {
|
||||||
public:
|
public:
|
||||||
static constexpr uint32_t BYTES_PROCESSED = 32;
|
static constexpr uint32_t BYTES_PROCESSED = 32;
|
||||||
|
// We only copy if dst is non-null.
|
||||||
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
||||||
|
|
||||||
simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
|
simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
|
||||||
@@ -34,8 +35,10 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin
|
|||||||
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
|
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
|
||||||
simd8<uint8_t> v0(src);
|
simd8<uint8_t> v0(src);
|
||||||
simd8<uint8_t> v1(src + sizeof(v0));
|
simd8<uint8_t> v1(src + sizeof(v0));
|
||||||
v0.store(dst);
|
if(dst != nullptr) {
|
||||||
v1.store(dst + sizeof(v0));
|
v0.store(dst);
|
||||||
|
v1.store(dst + sizeof(v0));
|
||||||
|
}
|
||||||
|
|
||||||
// Getting a 64-bit bitmask is much cheaper than multiple 16-bit bitmasks on ARM; therefore, we
|
// Getting a 64-bit bitmask is much cheaper than multiple 16-bit bitmasks on ARM; therefore, we
|
||||||
// smash them together into a 64-byte mask and get the bitmask from there.
|
// smash them together into a 64-byte mask and get the bitmask from there.
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef SIMDJSON_BUILDER_H
|
||||||
|
#define SIMDJSON_BUILDER_H
|
||||||
|
|
||||||
|
#include "simdjson/builtin/builder.h"
|
||||||
|
|
||||||
|
namespace simdjson {
|
||||||
|
/**
|
||||||
|
* @copydoc simdjson::builtin::builder
|
||||||
|
*/
|
||||||
|
namespace builder = builtin::builder;
|
||||||
|
|
||||||
|
} // namespace simdjson
|
||||||
|
|
||||||
|
#endif // SIMDJSON_BUILDER_H
|
||||||
@@ -20,10 +20,10 @@
|
|||||||
#include "simdjson/ppc64.h"
|
#include "simdjson/ppc64.h"
|
||||||
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(westmere)
|
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(westmere)
|
||||||
#include "simdjson/westmere.h"
|
#include "simdjson/westmere.h"
|
||||||
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(lsx)
|
|
||||||
#include "simdjson/lsx.h"
|
|
||||||
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(lasx)
|
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(lasx)
|
||||||
#include "simdjson/lasx.h"
|
#include "simdjson/lasx.h"
|
||||||
|
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(lsx)
|
||||||
|
#include "simdjson/lsx.h"
|
||||||
#else
|
#else
|
||||||
#error Unknown SIMDJSON_BUILTIN_IMPLEMENTATION
|
#error Unknown SIMDJSON_BUILTIN_IMPLEMENTATION
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#ifndef SIMDJSON_BUILTIN_BUILDER_H
|
||||||
|
#define SIMDJSON_BUILTIN_BUILDER_H
|
||||||
|
|
||||||
|
#include "simdjson/builtin.h"
|
||||||
|
#include "simdjson/builtin/base.h"
|
||||||
|
|
||||||
|
#include "simdjson/generic/builder/dependencies.h"
|
||||||
|
|
||||||
|
#define SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
|
|
||||||
|
#if SIMDJSON_BUILTIN_IMPLEMENTATION_IS(arm64)
|
||||||
|
#include "simdjson/arm64/builder.h"
|
||||||
|
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(fallback)
|
||||||
|
#include "simdjson/fallback/builder.h"
|
||||||
|
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(haswell)
|
||||||
|
#include "simdjson/haswell/builder.h"
|
||||||
|
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(icelake)
|
||||||
|
#include "simdjson/icelake/builder.h"
|
||||||
|
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(ppc64)
|
||||||
|
#include "simdjson/ppc64/builder.h"
|
||||||
|
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(westmere)
|
||||||
|
#include "simdjson/westmere/builder.h"
|
||||||
|
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(lsx)
|
||||||
|
#include "simdjson/lsx/builder.h"
|
||||||
|
#elif SIMDJSON_BUILTIN_IMPLEMENTATION_IS(lasx)
|
||||||
|
#include "simdjson/lasx/builder.h"
|
||||||
|
#else
|
||||||
|
#error Unknown SIMDJSON_BUILTIN_IMPLEMENTATION
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
|
|
||||||
|
namespace simdjson {
|
||||||
|
/**
|
||||||
|
* @copydoc simdjson::SIMDJSON_BUILTIN_IMPLEMENTATION::builder
|
||||||
|
*/
|
||||||
|
namespace builder = SIMDJSON_BUILTIN_IMPLEMENTATION::builder;
|
||||||
|
} // namespace simdjson
|
||||||
|
|
||||||
|
#endif // SIMDJSON_BUILTIN_BUILDER_H
|
||||||
@@ -289,7 +289,9 @@ namespace std {
|
|||||||
// when the compiler is optimizing.
|
// when the compiler is optimizing.
|
||||||
// We only set SIMDJSON_DEVELOPMENT_CHECKS if both __OPTIMIZE__
|
// We only set SIMDJSON_DEVELOPMENT_CHECKS if both __OPTIMIZE__
|
||||||
// and NDEBUG are not defined.
|
// and NDEBUG are not defined.
|
||||||
#if !defined(__OPTIMIZE__) && !defined(NDEBUG)
|
// We recognize _DEBUG as overriding __OPTIMIZE__ so that if both
|
||||||
|
// __OPTIMIZE__ and _DEBUG are defined, we still set SIMDJSON_DEVELOPMENT_CHECKS.
|
||||||
|
#if ((!defined(__OPTIMIZE__) || defined(_DEBUG)) && !defined(NDEBUG))
|
||||||
#define SIMDJSON_DEVELOPMENT_CHECKS 1
|
#define SIMDJSON_DEVELOPMENT_CHECKS 1
|
||||||
#endif // __OPTIMIZE__
|
#endif // __OPTIMIZE__
|
||||||
#endif // _MSC_VER
|
#endif // _MSC_VER
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* @file compile_time_json.h
|
||||||
|
* @brief Compile-time JSON parsing using C++26 reflection with
|
||||||
|
* std::meta::substitute()
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SIMDJSON_GENERIC_COMPILE_TIME_JSON_H
|
||||||
|
#define SIMDJSON_GENERIC_COMPILE_TIME_JSON_H
|
||||||
|
|
||||||
|
#if SIMDJSON_STATIC_REFLECTION
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
#include <charconv>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <expected>
|
||||||
|
#include <meta>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace simdjson {
|
||||||
|
namespace compile_time {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compile-time JSON parser. This function parses the provided JSON
|
||||||
|
* string at compile time and returns a custom struct type representing the JSON
|
||||||
|
* object.
|
||||||
|
*
|
||||||
|
* We have a few limitations which trigger compile-time errors if violated:
|
||||||
|
* - Only JSON objects and arrays are supported at the top level (no primitives).
|
||||||
|
* We will lift this limitation in the future.
|
||||||
|
* - Strings are represented using the const char * in UTF-8, but they must not
|
||||||
|
* contain embedded nulls. We would prefer to represent them as std::string or
|
||||||
|
* std::string_view, and hope to do so in the future.
|
||||||
|
* - Heterogeneous arrays are not supported yet. E.g., you need to have arrays of
|
||||||
|
* all integers, or all strings, all floats, all compatible objects, etc.
|
||||||
|
* For example, the following is accepted:
|
||||||
|
* [
|
||||||
|
* { "name": "Alice", "age": 30 },
|
||||||
|
* { "name": "Bob", "age": 25 },
|
||||||
|
* { "name": "Charlie", "age": 35 }
|
||||||
|
* ]
|
||||||
|
* but the following is not:
|
||||||
|
* [
|
||||||
|
* { "name": "Alice", "age": 30 },
|
||||||
|
* "Just a string",
|
||||||
|
* 42,
|
||||||
|
* { "name": "Charlie", "age": 35 }
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* We may support heterogeneous arrays in the future with std::variant types.
|
||||||
|
* - We parse the first JSON document encountered in the string. Trailing
|
||||||
|
* characters are ignored. Thus if your JSON begins with {"a":1}, everything
|
||||||
|
* after the closing } is ignored. This limitation will be lifted in the future,
|
||||||
|
* reporting an error.
|
||||||
|
*
|
||||||
|
* These limitations are safe in the sense that they result in compile-time errors.
|
||||||
|
* Thus you will not get truncated strings or imprecise floats silently.
|
||||||
|
*
|
||||||
|
* This function is subject to change in the future.
|
||||||
|
*/
|
||||||
|
template <constevalutil::fixed_string json_str> consteval auto parse_json();
|
||||||
|
|
||||||
|
} // namespace compile_time
|
||||||
|
} // namespace simdjson
|
||||||
|
|
||||||
|
|
||||||
|
template <simdjson::constevalutil::fixed_string str>
|
||||||
|
consteval auto operator ""_json() {
|
||||||
|
return simdjson::compile_time::parse_json<str>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SIMDJSON_STATIC_REFLECTION
|
||||||
|
#endif // SIMDJSON_GENERIC_COMPILE_TIME_JSON_H
|
||||||
@@ -13,6 +13,11 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// C++ 26
|
||||||
|
#if !defined(SIMDJSON_CPLUSPLUS26) && (SIMDJSON_CPLUSPLUS >= 202402L) // update when the standard is finalized
|
||||||
|
#define SIMDJSON_CPLUSPLUS26 1
|
||||||
|
#endif
|
||||||
|
|
||||||
// C++ 23
|
// C++ 23
|
||||||
#if !defined(SIMDJSON_CPLUSPLUS23) && (SIMDJSON_CPLUSPLUS >= 202302L)
|
#if !defined(SIMDJSON_CPLUSPLUS23) && (SIMDJSON_CPLUSPLUS >= 202302L)
|
||||||
#define SIMDJSON_CPLUSPLUS23 1
|
#define SIMDJSON_CPLUSPLUS23 1
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ consteval std::string consteval_to_quoted_escaped(std::string_view input) {
|
|||||||
|
|
||||||
|
|
||||||
#if SIMDJSON_SUPPORTS_CONCEPTS
|
#if SIMDJSON_SUPPORTS_CONCEPTS
|
||||||
template <std::size_t N>
|
template <size_t N>
|
||||||
struct fixed_string {
|
struct fixed_string {
|
||||||
constexpr fixed_string(const char (&str)[N]) {
|
constexpr fixed_string(const char (&str)[N]) {
|
||||||
for (std::size_t i = 0; i < N; ++i) {
|
for (std::size_t i = 0; i < N; ++i) {
|
||||||
@@ -60,6 +60,20 @@ struct fixed_string {
|
|||||||
}
|
}
|
||||||
char data[N];
|
char data[N];
|
||||||
constexpr std::string_view view() const { return {data, N - 1}; }
|
constexpr std::string_view view() const { return {data, N - 1}; }
|
||||||
|
constexpr size_t size() const { return N ; }
|
||||||
|
constexpr operator std::string_view() const { return view(); }
|
||||||
|
constexpr char operator[](std::size_t index) const { return data[index]; }
|
||||||
|
constexpr bool operator==(const fixed_string& other) const {
|
||||||
|
if (N != other.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (std::size_t i = 0; i < N; ++i) {
|
||||||
|
if (data[i] != other.data[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
fixed_string(const char (&)[N]) -> fixed_string<N>;
|
fixed_string(const char (&)[N]) -> fixed_string<N>;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "simdjson/dom/object.h"
|
#include "simdjson/dom/object.h"
|
||||||
#include "simdjson/dom/parser.h"
|
#include "simdjson/dom/parser.h"
|
||||||
#include "simdjson/dom/serialization.h"
|
#include "simdjson/dom/serialization.h"
|
||||||
|
#include "simdjson/dom/fractured_json.h"
|
||||||
|
|
||||||
// Inline functions
|
// Inline functions
|
||||||
#include "simdjson/dom/array-inl.h"
|
#include "simdjson/dom/array-inl.h"
|
||||||
@@ -19,5 +20,6 @@
|
|||||||
#include "simdjson/dom/parser-inl.h"
|
#include "simdjson/dom/parser-inl.h"
|
||||||
#include "simdjson/internal/tape_ref-inl.h"
|
#include "simdjson/internal/tape_ref-inl.h"
|
||||||
#include "simdjson/dom/serialization-inl.h"
|
#include "simdjson/dom/serialization-inl.h"
|
||||||
|
#include "simdjson/dom/fractured_json-inl.h"
|
||||||
|
|
||||||
#endif // SIMDJSON_DOM_H
|
#endif // SIMDJSON_DOM_H
|
||||||
|
|||||||
@@ -0,0 +1,159 @@
|
|||||||
|
#ifndef SIMDJSON_DOM_FRACTURED_JSON_H
|
||||||
|
#define SIMDJSON_DOM_FRACTURED_JSON_H
|
||||||
|
|
||||||
|
#include "simdjson/dom/base.h"
|
||||||
|
#include "simdjson/dom/element.h"
|
||||||
|
|
||||||
|
namespace simdjson {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration options for FracturedJson formatting.
|
||||||
|
*
|
||||||
|
* FracturedJson intelligently chooses between different layout strategies
|
||||||
|
* (inline, compact multiline, table, expanded) based on content complexity,
|
||||||
|
* length, and structure similarity.
|
||||||
|
*/
|
||||||
|
struct fractured_json_options {
|
||||||
|
/**
|
||||||
|
* Maximum total characters per line (default: 120).
|
||||||
|
* Content exceeding this will be expanded to multiple lines.
|
||||||
|
*/
|
||||||
|
size_t max_total_line_length = 120;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum length for inlined elements (default: 80).
|
||||||
|
* Simple arrays/objects shorter than this may be rendered inline.
|
||||||
|
*/
|
||||||
|
size_t max_inline_length = 80;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum nesting depth for inline rendering (default: 2).
|
||||||
|
* Elements with complexity exceeding this will be expanded.
|
||||||
|
* Complexity 0 = scalar, 1 = flat array/object, 2 = one level of nesting.
|
||||||
|
*/
|
||||||
|
size_t max_inline_complexity = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum complexity for compact array formatting (default: 1).
|
||||||
|
* Arrays with elements of this complexity or less may have multiple
|
||||||
|
* items per line.
|
||||||
|
*/
|
||||||
|
size_t max_compact_array_complexity = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of spaces per indentation level (default: 4).
|
||||||
|
*/
|
||||||
|
size_t indent_spaces = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable tabular formatting for arrays of similar objects (default: true).
|
||||||
|
* When enabled, arrays of objects with identical keys are formatted
|
||||||
|
* as aligned tables.
|
||||||
|
*/
|
||||||
|
bool enable_table_format = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimum number of rows to trigger table mode (default: 3).
|
||||||
|
*/
|
||||||
|
size_t min_table_rows = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similarity threshold for table detection (default: 0.8).
|
||||||
|
* Objects must share at least this fraction of keys to be formatted
|
||||||
|
* as a table.
|
||||||
|
*/
|
||||||
|
double table_similarity_threshold = 0.8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable compact multiline arrays (default: true).
|
||||||
|
* When enabled, arrays of simple elements may have multiple items
|
||||||
|
* per line.
|
||||||
|
*/
|
||||||
|
bool enable_compact_multiline = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum array items per line in compact mode (default: 10).
|
||||||
|
*/
|
||||||
|
size_t max_items_per_line = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add space inside brackets for simple containers (default: true).
|
||||||
|
* When true: { "key": "value" }
|
||||||
|
* When false: {"key": "value"}
|
||||||
|
*/
|
||||||
|
bool simple_bracket_padding = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add space after colons (default: true).
|
||||||
|
* When true: "key": "value"
|
||||||
|
* When false: "key":"value"
|
||||||
|
*/
|
||||||
|
bool colon_padding = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add space after commas in inline content (default: true).
|
||||||
|
* When true: [1, 2, 3]
|
||||||
|
* When false: [1,2,3]
|
||||||
|
*/
|
||||||
|
bool comma_padding = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format JSON using FracturedJson formatting with default options.
|
||||||
|
*
|
||||||
|
* FracturedJson produces human-readable yet compact output by intelligently
|
||||||
|
* choosing between inline, compact multiline, table, and expanded layouts.
|
||||||
|
*
|
||||||
|
* dom::parser parser;
|
||||||
|
* element doc = parser.parse(json_string);
|
||||||
|
* cout << fractured_json(doc) << endl;
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
std::string fractured_json(T x);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format JSON using FracturedJson formatting with custom options.
|
||||||
|
*
|
||||||
|
* dom::parser parser;
|
||||||
|
* element doc = parser.parse(json_string);
|
||||||
|
* fractured_json_options opts;
|
||||||
|
* opts.max_total_line_length = 80;
|
||||||
|
* cout << fractured_json(doc, opts) << endl;
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
std::string fractured_json(T x, const fractured_json_options& options);
|
||||||
|
|
||||||
|
#if SIMDJSON_EXCEPTIONS
|
||||||
|
template <class T>
|
||||||
|
std::string fractured_json(simdjson_result<T> x);
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
std::string fractured_json(simdjson_result<T> x, const fractured_json_options& options);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a JSON string using FracturedJson formatting.
|
||||||
|
*
|
||||||
|
* This is useful for formatting output from the builder/static reflection API
|
||||||
|
* or any valid JSON string.
|
||||||
|
*
|
||||||
|
* // With static reflection
|
||||||
|
* MyStruct data = {...};
|
||||||
|
* auto minified = simdjson::to_json_string(data);
|
||||||
|
* auto formatted = simdjson::fractured_json_string(minified.value());
|
||||||
|
*
|
||||||
|
* // Or with any JSON string
|
||||||
|
* std::string json = R"({"key":"value"})";
|
||||||
|
* auto formatted = simdjson::fractured_json_string(json);
|
||||||
|
*/
|
||||||
|
inline std::string fractured_json_string(std::string_view json_str);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a JSON string using FracturedJson formatting with custom options.
|
||||||
|
*/
|
||||||
|
inline std::string fractured_json_string(std::string_view json_str,
|
||||||
|
const fractured_json_options& options);
|
||||||
|
|
||||||
|
} // namespace simdjson
|
||||||
|
|
||||||
|
#endif // SIMDJSON_DOM_FRACTURED_JSON_H
|
||||||
@@ -204,10 +204,7 @@ public:
|
|||||||
*
|
*
|
||||||
* ### std::string references
|
* ### std::string references
|
||||||
*
|
*
|
||||||
* If you pass a mutable std::string reference (std::string&), the parser will seek to extend
|
* Whenever you pass an std::string reference, the parser may access the bytes beyond the end of
|
||||||
* its capacity to SIMDJSON_PADDING bytes beyond the end of the string.
|
|
||||||
*
|
|
||||||
* Whenever you pass an std::string reference, the parser will access the bytes beyond the end of
|
|
||||||
* the string but before the end of the allocated memory (std::string::capacity()).
|
* the string but before the end of the allocated memory (std::string::capacity()).
|
||||||
* If you are using a sanitizer that checks for reading uninitialized bytes or std::string's
|
* If you are using a sanitizer that checks for reading uninitialized bytes or std::string's
|
||||||
* container-overflow checks, you may encounter sanitizer warnings.
|
* container-overflow checks, you may encounter sanitizer warnings.
|
||||||
@@ -239,7 +236,7 @@ public:
|
|||||||
/** @overload parse(const uint8_t *buf, size_t len, bool realloc_if_needed) */
|
/** @overload parse(const uint8_t *buf, size_t len, bool realloc_if_needed) */
|
||||||
simdjson_inline simdjson_result<element> parse(const char *buf, size_t len, bool realloc_if_needed = true) & noexcept;
|
simdjson_inline simdjson_result<element> parse(const char *buf, size_t len, bool realloc_if_needed = true) & noexcept;
|
||||||
simdjson_inline simdjson_result<element> parse(const char *buf, size_t len, bool realloc_if_needed = true) && =delete;
|
simdjson_inline simdjson_result<element> parse(const char *buf, size_t len, bool realloc_if_needed = true) && =delete;
|
||||||
/** @overload parse(const uint8_t *buf, size_t len, bool realloc_if_needed) */
|
/** @overload parse(const std::string &) */
|
||||||
simdjson_inline simdjson_result<element> parse(const std::string &s) & noexcept;
|
simdjson_inline simdjson_result<element> parse(const std::string &s) & noexcept;
|
||||||
simdjson_inline simdjson_result<element> parse(const std::string &s) && =delete;
|
simdjson_inline simdjson_result<element> parse(const std::string &s) && =delete;
|
||||||
/** @overload parse(const uint8_t *buf, size_t len, bool realloc_if_needed) */
|
/** @overload parse(const uint8_t *buf, size_t len, bool realloc_if_needed) */
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
namespace simdjson {
|
namespace simdjson {
|
||||||
|
|
||||||
inline bool is_fatal(error_code error) noexcept {
|
inline bool is_fatal(error_code error) noexcept {
|
||||||
return error == TAPE_ERROR || error == INCOMPLETE_ARRAY_OR_OBJECT;
|
return error == TAPE_ERROR || error == INCOMPLETE_ARRAY_OR_OBJECT || error == OUT_OF_ORDER_ITERATION || error == DEPTH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|||||||
@@ -265,6 +265,8 @@ struct simdjson_result_base : protected std::pair<T, error_code> {
|
|||||||
*/
|
*/
|
||||||
simdjson_inline T&& value_unsafe() && noexcept;
|
simdjson_inline T&& value_unsafe() && noexcept;
|
||||||
|
|
||||||
|
using value_type = T;
|
||||||
|
using error_type = error_code;
|
||||||
}; // struct simdjson_result_base
|
}; // struct simdjson_result_base
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
@@ -376,6 +378,8 @@ struct simdjson_result : public internal::simdjson_result_base<T> {
|
|||||||
*/
|
*/
|
||||||
simdjson_inline T&& value_unsafe() && noexcept;
|
simdjson_inline T&& value_unsafe() && noexcept;
|
||||||
|
|
||||||
|
using value_type = T;
|
||||||
|
using error_type = error_code;
|
||||||
}; // struct simdjson_result
|
}; // struct simdjson_result
|
||||||
|
|
||||||
#if SIMDJSON_EXCEPTIONS
|
#if SIMDJSON_EXCEPTIONS
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef SIMDJSON_FALLBACK_BUILDER_H
|
||||||
|
#define SIMDJSON_FALLBACK_BUILDER_H
|
||||||
|
|
||||||
|
#include "simdjson/fallback/begin.h"
|
||||||
|
#include "simdjson/generic/builder/amalgamated.h"
|
||||||
|
#include "simdjson/fallback/end.h"
|
||||||
|
|
||||||
|
#endif // SIMDJSON_FALLBACK_BUILDER_H
|
||||||
@@ -13,6 +13,7 @@ namespace {
|
|||||||
struct backslash_and_quote {
|
struct backslash_and_quote {
|
||||||
public:
|
public:
|
||||||
static constexpr uint32_t BYTES_PROCESSED = 1;
|
static constexpr uint32_t BYTES_PROCESSED = 1;
|
||||||
|
// We only copy if dst is non-null.
|
||||||
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
||||||
|
|
||||||
simdjson_inline bool has_quote_first() { return c == '"'; }
|
simdjson_inline bool has_quote_first() { return c == '"'; }
|
||||||
@@ -25,7 +26,9 @@ public:
|
|||||||
|
|
||||||
simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
|
simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8_t *src, uint8_t *dst) {
|
||||||
// store to dest unconditionally - we can overwrite the bits we don't like later
|
// store to dest unconditionally - we can overwrite the bits we don't like later
|
||||||
dst[0] = src[0];
|
if(dst != nullptr) {
|
||||||
|
dst[0] = src[0];
|
||||||
|
}
|
||||||
return { src[0] };
|
return { src[0] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,10 @@
|
|||||||
#include "simdjson/arm64/begin.h"
|
#include "simdjson/arm64/begin.h"
|
||||||
#elif SIMDJSON_IMPLEMENTATION_PPC64
|
#elif SIMDJSON_IMPLEMENTATION_PPC64
|
||||||
#include "simdjson/ppc64/begin.h"
|
#include "simdjson/ppc64/begin.h"
|
||||||
#elif SIMDJSON_IMPLEMENTATION_LSX
|
|
||||||
#include "simdjson/lsx/begin.h"
|
|
||||||
#elif SIMDJSON_IMPLEMENTATION_LASX
|
#elif SIMDJSON_IMPLEMENTATION_LASX
|
||||||
#include "simdjson/lasx/begin.h"
|
#include "simdjson/lasx/begin.h"
|
||||||
|
#elif SIMDJSON_IMPLEMENTATION_LSX
|
||||||
|
#include "simdjson/lsx/begin.h"
|
||||||
#elif SIMDJSON_IMPLEMENTATION_FALLBACK
|
#elif SIMDJSON_IMPLEMENTATION_FALLBACK
|
||||||
#include "simdjson/fallback/begin.h"
|
#include "simdjson/fallback/begin.h"
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#if defined(SIMDJSON_CONDITIONAL_INCLUDE) && !defined(SIMDJSON_GENERIC_BUILDER_DEPENDENCIES_H)
|
||||||
|
#error simdjson/generic/builder/dependencies.h must be included before simdjson/generic/builder/amalgamated.h!
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "simdjson/generic/builder/json_string_builder.h"
|
||||||
|
#include "simdjson/generic/builder/json_builder.h"
|
||||||
|
#include "simdjson/generic/builder/fractured_json_builder.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// JSON builder inline definitions
|
||||||
|
#include "simdjson/generic/builder/json_string_builder-inl.h"
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#ifdef SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
|
#error simdjson/generic/builder/dependencies.h must be included before defining SIMDJSON_CONDITIONAL_INCLUDE!
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIMDJSON_GENERIC_BUILDER_DEPENDENCIES_H
|
||||||
|
#define SIMDJSON_GENERIC_BUILDER_DEPENDENCIES_H
|
||||||
|
|
||||||
|
// Internal headers needed for builder generics.
|
||||||
|
// All includes not under simdjson/generic/builder must be here!
|
||||||
|
// Otherwise, amalgamation will fail.
|
||||||
|
#include "simdjson/concepts.h"
|
||||||
|
#include "simdjson/dom/fractured_json.h"
|
||||||
|
|
||||||
|
#endif // SIMDJSON_GENERIC_BUILDER_DEPENDENCIES_H
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
#ifndef SIMDJSON_GENERIC_FRACTURED_JSON_BUILDER_H
|
||||||
|
#define SIMDJSON_GENERIC_FRACTURED_JSON_BUILDER_H
|
||||||
|
|
||||||
|
#ifndef SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
|
#include "simdjson/generic/builder/json_builder.h"
|
||||||
|
#include "simdjson/dom/fractured_json.h"
|
||||||
|
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
|
|
||||||
|
#if SIMDJSON_STATIC_REFLECTION
|
||||||
|
|
||||||
|
namespace simdjson {
|
||||||
|
namespace SIMDJSON_IMPLEMENTATION {
|
||||||
|
namespace builder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize an object to a FracturedJson-formatted string.
|
||||||
|
*
|
||||||
|
* FracturedJson produces human-readable yet compact JSON output by intelligently
|
||||||
|
* choosing between different layout strategies (inline, compact multiline, table,
|
||||||
|
* expanded) based on content complexity, length, and structure similarity.
|
||||||
|
*
|
||||||
|
* This function combines the builder's serialization with FracturedJson formatting:
|
||||||
|
* 1. Serializes the object to minified JSON using reflection
|
||||||
|
* 2. Parses and reformats using FracturedJson
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* struct User { int id; std::string name; bool active; };
|
||||||
|
* User user{1, "Alice", true};
|
||||||
|
* auto result = to_fractured_json_string(user);
|
||||||
|
* // result.value() == "{ \"id\": 1, \"name\": \"Alice\", \"active\": true }"
|
||||||
|
*
|
||||||
|
* @param obj The object to serialize (must be a reflectable type)
|
||||||
|
* @param opts FracturedJson formatting options
|
||||||
|
* @param initial_capacity Initial buffer capacity for serialization
|
||||||
|
* @return The formatted JSON string, or an error
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
simdjson_warn_unused simdjson_result<std::string> to_fractured_json_string(
|
||||||
|
const T& obj,
|
||||||
|
const fractured_json_options& opts = {},
|
||||||
|
size_t initial_capacity = string_builder::DEFAULT_INITIAL_CAPACITY) {
|
||||||
|
// Step 1: Serialize to minified JSON
|
||||||
|
std::string formatted;
|
||||||
|
auto error = to_json_string(obj, initial_capacity).get(formatted);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: Reformat with FracturedJson
|
||||||
|
return fractured_json_string(formatted, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract specific fields from an object and format with FracturedJson.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* struct User { int id; std::string name; std::string email; bool active; };
|
||||||
|
* User user{1, "Alice", "alice@example.com", true};
|
||||||
|
* auto result = extract_fractured_json<"id", "name">(user);
|
||||||
|
* // result.value() == "{ \"id\": 1, \"name\": \"Alice\" }"
|
||||||
|
*
|
||||||
|
* @param obj The object to serialize
|
||||||
|
* @param opts FracturedJson formatting options
|
||||||
|
* @param initial_capacity Initial buffer capacity for serialization
|
||||||
|
* @return The formatted JSON string containing only the specified fields
|
||||||
|
*/
|
||||||
|
template<constevalutil::fixed_string... FieldNames, typename T>
|
||||||
|
requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
|
||||||
|
simdjson_warn_unused simdjson_result<std::string> extract_fractured_json(
|
||||||
|
const T& obj,
|
||||||
|
const fractured_json_options& opts = {},
|
||||||
|
size_t initial_capacity = string_builder::DEFAULT_INITIAL_CAPACITY) {
|
||||||
|
// Step 1: Extract fields to minified JSON
|
||||||
|
std::string formatted;
|
||||||
|
auto error = extract_from<FieldNames...>(obj, initial_capacity).get(formatted);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: Reformat with FracturedJson
|
||||||
|
return fractured_json_string(formatted, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace builder
|
||||||
|
} // namespace SIMDJSON_IMPLEMENTATION
|
||||||
|
|
||||||
|
// Global namespace convenience functions
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize an object to a FracturedJson-formatted string.
|
||||||
|
* Global namespace version for convenience.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
simdjson_warn_unused simdjson_result<std::string> to_fractured_json_string(
|
||||||
|
const T& obj,
|
||||||
|
const fractured_json_options& opts = {},
|
||||||
|
size_t initial_capacity = SIMDJSON_IMPLEMENTATION::builder::string_builder::DEFAULT_INITIAL_CAPACITY) {
|
||||||
|
return SIMDJSON_IMPLEMENTATION::builder::to_fractured_json_string(obj, opts, initial_capacity);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Extract specific fields from an object and format with FracturedJson.
|
||||||
|
* Global namespace version for convenience.
|
||||||
|
*/
|
||||||
|
template<constevalutil::fixed_string... FieldNames, typename T>
|
||||||
|
requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
|
||||||
|
simdjson_warn_unused simdjson_result<std::string> extract_fractured_json(
|
||||||
|
const T& obj,
|
||||||
|
const fractured_json_options& opts = {},
|
||||||
|
size_t initial_capacity = SIMDJSON_IMPLEMENTATION::builder::string_builder::DEFAULT_INITIAL_CAPACITY) {
|
||||||
|
return SIMDJSON_IMPLEMENTATION::builder::extract_fractured_json<FieldNames...>(obj, opts, initial_capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace simdjson
|
||||||
|
|
||||||
|
#endif // SIMDJSON_STATIC_REFLECTION
|
||||||
|
|
||||||
|
#endif // SIMDJSON_GENERIC_FRACTURED_JSON_BUILDER_H
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
/**
|
|
||||||
* This file is part of the builder API. It is temporarily in the ondemand directory
|
|
||||||
* but we will move it to a builder directory later.
|
|
||||||
*/
|
|
||||||
#ifndef SIMDJSON_GENERIC_BUILDER_H
|
#ifndef SIMDJSON_GENERIC_BUILDER_H
|
||||||
|
|
||||||
#ifndef SIMDJSON_CONDITIONAL_INCLUDE
|
#ifndef SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
/**
|
|
||||||
* This file is part of the builder API. It is temporarily in the ondemand
|
|
||||||
* directory but we will move it to a builder directory later.
|
|
||||||
*/
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -519,8 +515,8 @@ simdjson_inline void string_builder::append(const T &opt) {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
requires(require_custom_serialization<T>)
|
requires(require_custom_serialization<T>)
|
||||||
simdjson_inline void string_builder::append(const T &val) {
|
simdjson_inline void string_builder::append(T &&val) {
|
||||||
serialize(*this, val);
|
serialize(*this, std::forward<T>(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -534,11 +530,11 @@ simdjson_inline void string_builder::append(const T &value) {
|
|||||||
#if SIMDJSON_SUPPORTS_RANGES && SIMDJSON_SUPPORTS_CONCEPTS
|
#if SIMDJSON_SUPPORTS_RANGES && SIMDJSON_SUPPORTS_CONCEPTS
|
||||||
// Support for range-based appending (std::ranges::view, etc.)
|
// Support for range-based appending (std::ranges::view, etc.)
|
||||||
template <std::ranges::range R>
|
template <std::ranges::range R>
|
||||||
requires(!std::is_convertible<R, std::string_view>::value)
|
requires(!std::is_convertible<R, std::string_view>::value && !require_custom_serialization<R>)
|
||||||
simdjson_inline void string_builder::append(const R &range) noexcept {
|
simdjson_inline void string_builder::append(const R &range) noexcept {
|
||||||
auto it = std::ranges::begin(range);
|
auto it = std::ranges::begin(range);
|
||||||
auto end = std::ranges::end(range);
|
auto end = std::ranges::end(range);
|
||||||
if constexpr (concepts::is_pair<typename R::value_type>) {
|
if constexpr (concepts::is_pair<std::ranges::range_value_t<R>>) {
|
||||||
start_object();
|
start_object();
|
||||||
|
|
||||||
if (it == end) {
|
if (it == end) {
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
/**
|
|
||||||
* This file is part of the builder API. It is temporarily in the ondemand directory
|
|
||||||
* but we will move it to a builder directory later.
|
|
||||||
*/
|
|
||||||
#ifndef SIMDJSON_GENERIC_STRING_BUILDER_H
|
#ifndef SIMDJSON_GENERIC_STRING_BUILDER_H
|
||||||
|
|
||||||
#ifndef SIMDJSON_CONDITIONAL_INCLUDE
|
#ifndef SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
@@ -24,9 +20,8 @@ struct has_custom_serialization : std::false_type {};
|
|||||||
|
|
||||||
inline constexpr struct serialize_tag {
|
inline constexpr struct serialize_tag {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
requires custom_deserializable<T>
|
constexpr void operator()(SIMDJSON_IMPLEMENTATION::builder::string_builder& b, T&& obj) const{
|
||||||
constexpr void operator()(SIMDJSON_IMPLEMENTATION::builder::string_builder& b, T& obj) const{
|
return tag_invoke(*this, b, std::forward<T>(obj));
|
||||||
return tag_invoke(*this, b, obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -165,7 +160,7 @@ public:
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
requires(require_custom_serialization<T>)
|
requires(require_custom_serialization<T>)
|
||||||
simdjson_inline void append(const T &val);
|
simdjson_inline void append(T &&val);
|
||||||
|
|
||||||
// Support for string-like types
|
// Support for string-like types
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -176,7 +171,7 @@ public:
|
|||||||
#if SIMDJSON_SUPPORTS_RANGES && SIMDJSON_SUPPORTS_CONCEPTS
|
#if SIMDJSON_SUPPORTS_RANGES && SIMDJSON_SUPPORTS_CONCEPTS
|
||||||
// Support for range-based appending (std::ranges::view, etc.)
|
// Support for range-based appending (std::ranges::view, etc.)
|
||||||
template <std::ranges::range R>
|
template <std::ranges::range R>
|
||||||
requires (!std::is_convertible<R, std::string_view>::value)
|
requires (!std::is_convertible<R, std::string_view>::value && !require_custom_serialization<R>)
|
||||||
simdjson_inline void append(const R &range) noexcept;
|
simdjson_inline void append(const R &range) noexcept;
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
@@ -40,6 +40,7 @@ public:
|
|||||||
simdjson_warn_unused error_code stage1(const uint8_t *buf, size_t len, stage1_mode partial) noexcept final;
|
simdjson_warn_unused error_code stage1(const uint8_t *buf, size_t len, stage1_mode partial) noexcept final;
|
||||||
simdjson_warn_unused error_code stage2(dom::document &doc) noexcept final;
|
simdjson_warn_unused error_code stage2(dom::document &doc) noexcept final;
|
||||||
simdjson_warn_unused error_code stage2_next(dom::document &doc) noexcept final;
|
simdjson_warn_unused error_code stage2_next(dom::document &doc) noexcept final;
|
||||||
|
simdjson_warn_unused std::pair<const uint8_t *,bool> parse_string_if_needed(const uint8_t *src, uint8_t *dst, bool allow_replacement) const noexcept final;
|
||||||
simdjson_warn_unused uint8_t *parse_string(const uint8_t *src, uint8_t *dst, bool allow_replacement) const noexcept final;
|
simdjson_warn_unused uint8_t *parse_string(const uint8_t *src, uint8_t *dst, bool allow_replacement) const noexcept final;
|
||||||
simdjson_warn_unused uint8_t *parse_wobbly_string(const uint8_t *src, uint8_t *dst) const noexcept final;
|
simdjson_warn_unused uint8_t *parse_wobbly_string(const uint8_t *src, uint8_t *dst) const noexcept final;
|
||||||
inline simdjson_warn_unused error_code set_capacity(size_t capacity) noexcept final;
|
inline simdjson_warn_unused error_code set_capacity(size_t capacity) noexcept final;
|
||||||
|
|||||||
@@ -138,6 +138,9 @@ struct implementation_simdjson_result_base {
|
|||||||
*/
|
*/
|
||||||
simdjson_inline T&& value_unsafe() && noexcept;
|
simdjson_inline T&& value_unsafe() && noexcept;
|
||||||
|
|
||||||
|
using value_type = T;
|
||||||
|
using error_type = error_code;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** users should never directly access first and second. **/
|
/** users should never directly access first and second. **/
|
||||||
T first{}; /** Users should never directly access 'first'. **/
|
T first{}; /** Users should never directly access 'first'. **/
|
||||||
|
|||||||
@@ -167,7 +167,12 @@ simdjson_inline bool compute_float_64(int64_t power, uint64_t i, bool negative,
|
|||||||
// with a returned value of type value128 with a "low component" corresponding to the
|
// with a returned value of type value128 with a "low component" corresponding to the
|
||||||
// 64-bit least significant bits of the product and with a "high component" corresponding
|
// 64-bit least significant bits of the product and with a "high component" corresponding
|
||||||
// to the 64-bit most significant bits of the product.
|
// to the 64-bit most significant bits of the product.
|
||||||
|
#if SIMDJSON_STATIC_REFLECTION
|
||||||
|
simdjson::internal::value128 firstproduct = full_multiplication(i, simdjson::internal::powers_template<>::power_of_five_128[index]);
|
||||||
|
#else
|
||||||
simdjson::internal::value128 firstproduct = full_multiplication(i, simdjson::internal::power_of_five_128[index]);
|
simdjson::internal::value128 firstproduct = full_multiplication(i, simdjson::internal::power_of_five_128[index]);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Both i and power_of_five_128[index] have their most significant bit set to 1 which
|
// Both i and power_of_five_128[index] have their most significant bit set to 1 which
|
||||||
// implies that the either the most or the second most significant bit of the product
|
// implies that the either the most or the second most significant bit of the product
|
||||||
// is 1. We pack values in this manner for efficiency reasons: it maximizes the use
|
// is 1. We pack values in this manner for efficiency reasons: it maximizes the use
|
||||||
@@ -200,7 +205,11 @@ simdjson_inline bool compute_float_64(int64_t power, uint64_t i, bool negative,
|
|||||||
// with a returned value of type value128 with a "low component" corresponding to the
|
// with a returned value of type value128 with a "low component" corresponding to the
|
||||||
// 64-bit least significant bits of the product and with a "high component" corresponding
|
// 64-bit least significant bits of the product and with a "high component" corresponding
|
||||||
// to the 64-bit most significant bits of the product.
|
// to the 64-bit most significant bits of the product.
|
||||||
|
#if SIMDJSON_STATIC_REFLECTION
|
||||||
|
simdjson::internal::value128 secondproduct = full_multiplication(i, simdjson::internal::powers_template<>::power_of_five_128[index + 1]);
|
||||||
|
#else
|
||||||
simdjson::internal::value128 secondproduct = full_multiplication(i, simdjson::internal::power_of_five_128[index + 1]);
|
simdjson::internal::value128 secondproduct = full_multiplication(i, simdjson::internal::power_of_five_128[index + 1]);
|
||||||
|
#endif
|
||||||
firstproduct.low += secondproduct.high;
|
firstproduct.low += secondproduct.high;
|
||||||
if(secondproduct.high > firstproduct.low) { firstproduct.high++; }
|
if(secondproduct.high > firstproduct.low) { firstproduct.high++; }
|
||||||
// As it has been proven by Noble Mushtak and Daniel Lemire in "Fast Number Parsing Without
|
// As it has been proven by Noble Mushtak and Daniel Lemire in "Fast Number Parsing Without
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#if defined(SIMDJSON_CONDITIONAL_INCLUDE) && !defined(SIMDJSON_GENERIC_ONDEMAND_DEPENDENCIES_H)
|
#if defined(SIMDJSON_CONDITIONAL_INCLUDE) && !defined(SIMDJSON_GENERIC_BUILDER_DEPENDENCIES_H)
|
||||||
#error simdjson/generic/ondemand/dependencies.h must be included before simdjson/generic/ondemand/amalgamated.h!
|
#error simdjson/generic/ondemand/dependencies.h must be included before simdjson/generic/ondemand/amalgamated.h!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -14,9 +14,6 @@
|
|||||||
#include "simdjson/generic/ondemand/raw_json_string.h"
|
#include "simdjson/generic/ondemand/raw_json_string.h"
|
||||||
#include "simdjson/generic/ondemand/parser.h"
|
#include "simdjson/generic/ondemand/parser.h"
|
||||||
|
|
||||||
// JSON builder - needed for extract_into functionality
|
|
||||||
#include "simdjson/generic/ondemand/json_string_builder.h"
|
|
||||||
|
|
||||||
// All other declarations
|
// All other declarations
|
||||||
#include "simdjson/generic/ondemand/array.h"
|
#include "simdjson/generic/ondemand/array.h"
|
||||||
#include "simdjson/generic/ondemand/array_iterator.h"
|
#include "simdjson/generic/ondemand/array_iterator.h"
|
||||||
@@ -44,13 +41,9 @@
|
|||||||
#include "simdjson/generic/ondemand/object_iterator-inl.h"
|
#include "simdjson/generic/ondemand/object_iterator-inl.h"
|
||||||
#include "simdjson/generic/ondemand/parser-inl.h"
|
#include "simdjson/generic/ondemand/parser-inl.h"
|
||||||
#include "simdjson/generic/ondemand/raw_json_string-inl.h"
|
#include "simdjson/generic/ondemand/raw_json_string-inl.h"
|
||||||
#include "simdjson/generic/ondemand/serialization-inl.h"
|
|
||||||
#include "simdjson/generic/ondemand/token_iterator-inl.h"
|
#include "simdjson/generic/ondemand/token_iterator-inl.h"
|
||||||
#include "simdjson/generic/ondemand/value_iterator-inl.h"
|
#include "simdjson/generic/ondemand/value_iterator-inl.h"
|
||||||
|
#include "simdjson/generic/ondemand/serialization-inl.h"
|
||||||
// JSON builder inline definitions
|
|
||||||
#include "simdjson/generic/ondemand/json_string_builder-inl.h"
|
|
||||||
#include "simdjson/generic/ondemand/json_builder.h"
|
|
||||||
|
|
||||||
// JSON path accessor (compile-time) - must be after inline definitions
|
// JSON path accessor (compile-time) - must be after inline definitions
|
||||||
#include "simdjson/generic/ondemand/compile_time_accessors.h"
|
#include "simdjson/generic/ondemand/compile_time_accessors.h"
|
||||||
|
|||||||
@@ -170,6 +170,67 @@ inline simdjson_result<value> array::at_path(std::string_view json_path) noexcep
|
|||||||
return at_pointer(json_pointer);
|
return at_pointer(json_pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline simdjson_result<std::vector<value>> array::at_path_with_wildcard(std::string_view json_path) noexcept {
|
||||||
|
std::vector<value> result;
|
||||||
|
|
||||||
|
auto result_pair = get_next_key_and_json_path(json_path);
|
||||||
|
std::string_view key = result_pair.first;
|
||||||
|
std::string_view remaining_path = result_pair.second;
|
||||||
|
// Wildcard case
|
||||||
|
if(key=="*"){
|
||||||
|
for(auto element: *this){
|
||||||
|
|
||||||
|
if(element.error()){
|
||||||
|
return element.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(remaining_path.empty()){
|
||||||
|
// Use value_unsafe() because we've already checked for errors above.
|
||||||
|
// The 'element' is a simdjson_result<value> wrapper, and we need to extract
|
||||||
|
// the underlying value. value_unsafe() is safe here because error() returned false.
|
||||||
|
result.push_back(std::move(element).value_unsafe());
|
||||||
|
|
||||||
|
}else{
|
||||||
|
auto nested_result = element.at_path_with_wildcard(remaining_path);
|
||||||
|
|
||||||
|
if(nested_result.error()){
|
||||||
|
return nested_result.error();
|
||||||
|
}
|
||||||
|
// Same logic as above.
|
||||||
|
std::vector<value> nested_matches = std::move(nested_result).value_unsafe();
|
||||||
|
|
||||||
|
result.insert(result.end(),
|
||||||
|
std::make_move_iterator(nested_matches.begin()),
|
||||||
|
std::make_move_iterator(nested_matches.end()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}else{
|
||||||
|
// Specific index case in which we access the element at the given index
|
||||||
|
size_t idx=0;
|
||||||
|
|
||||||
|
for(char c:key){
|
||||||
|
if(c < '0' || c > '9'){
|
||||||
|
return INVALID_JSON_POINTER;
|
||||||
|
}
|
||||||
|
idx = idx*10 + (c - '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
auto element = at(idx);
|
||||||
|
|
||||||
|
if(element.error()){
|
||||||
|
return element.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(remaining_path.empty()){
|
||||||
|
result.push_back(std::move(element).value_unsafe());
|
||||||
|
return result;
|
||||||
|
}else{
|
||||||
|
return element.at_path_with_wildcard(remaining_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
simdjson_inline simdjson_result<value> array::at(size_t index) noexcept {
|
simdjson_inline simdjson_result<value> array::at(size_t index) noexcept {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (auto value : *this) {
|
for (auto value : *this) {
|
||||||
@@ -228,6 +289,10 @@ simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdj
|
|||||||
if (error()) { return error(); }
|
if (error()) { return error(); }
|
||||||
return first.at_path(json_path);
|
return first.at_path(json_path);
|
||||||
}
|
}
|
||||||
|
simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::at_path_with_wildcard(std::string_view json_path) noexcept {
|
||||||
|
if (error()) { return error(); }
|
||||||
|
return first.at_path_with_wildcard(json_path);
|
||||||
|
}
|
||||||
simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::raw_json() noexcept {
|
simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array>::raw_json() noexcept {
|
||||||
if (error()) { return error(); }
|
if (error()) { return error(); }
|
||||||
return first.raw_json();
|
return first.raw_json();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "simdjson/generic/ondemand/base.h"
|
#include "simdjson/generic/ondemand/base.h"
|
||||||
#include "simdjson/generic/implementation_simdjson_result_base.h"
|
#include "simdjson/generic/implementation_simdjson_result_base.h"
|
||||||
#include "simdjson/generic/ondemand/value_iterator.h"
|
#include "simdjson/generic/ondemand/value_iterator.h"
|
||||||
|
#include <vector>
|
||||||
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
|
|
||||||
namespace simdjson {
|
namespace simdjson {
|
||||||
@@ -117,6 +118,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
|
inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all values matching the given JSONPath expression with wildcard support.
|
||||||
|
* Supports wildcard patterns like "[*]" to match all array elements.
|
||||||
|
*
|
||||||
|
* @param json_path JSONPath expression with wildcards
|
||||||
|
* @return Vector of values matching the wildcard pattern
|
||||||
|
*/
|
||||||
|
inline simdjson_result<std::vector<value>> at_path_with_wildcard(std::string_view json_path) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consumes the array and returns a string_view instance corresponding to the
|
* Consumes the array and returns a string_view instance corresponding to the
|
||||||
* array as represented in JSON. It points inside the original document.
|
* array as represented in JSON. It points inside the original document.
|
||||||
@@ -239,6 +249,7 @@ public:
|
|||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at(size_t index) noexcept;
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
|
||||||
|
simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> at_path_with_wildcard(std::string_view json_path) noexcept;
|
||||||
simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
|
simdjson_inline simdjson_result<std::string_view> raw_json() noexcept;
|
||||||
#if SIMDJSON_SUPPORTS_CONCEPTS
|
#if SIMDJSON_SUPPORTS_CONCEPTS
|
||||||
// TODO: move this code into object-inl.h
|
// TODO: move this code into object-inl.h
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ simdjson_inline array_iterator::array_iterator(const value_iterator &_iter) noex
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
simdjson_inline simdjson_result<value> array_iterator::operator*() noexcept {
|
simdjson_inline simdjson_result<value> array_iterator::operator*() noexcept {
|
||||||
|
#if SIMDJSON_DEVELOPMENT_CHECKS
|
||||||
|
SIMDJSON_ASSUME(!has_been_referenced);
|
||||||
|
has_been_referenced = true;
|
||||||
|
#endif
|
||||||
if (iter.error()) { iter.abandon(); return iter.error(); }
|
if (iter.error()) { iter.abandon(); return iter.error(); }
|
||||||
return value(iter.child());
|
return value(iter.child());
|
||||||
}
|
}
|
||||||
@@ -27,6 +31,9 @@ simdjson_inline bool array_iterator::operator!=(const array_iterator &) const no
|
|||||||
return iter.is_open();
|
return iter.is_open();
|
||||||
}
|
}
|
||||||
simdjson_inline array_iterator &array_iterator::operator++() noexcept {
|
simdjson_inline array_iterator &array_iterator::operator++() noexcept {
|
||||||
|
#if SIMDJSON_DEVELOPMENT_CHECKS
|
||||||
|
has_been_referenced = false;
|
||||||
|
#endif
|
||||||
error_code error;
|
error_code error;
|
||||||
// PERF NOTE this is a safety rail ... users should exit loops as soon as they receive an error, so we'll never get here.
|
// PERF NOTE this is a safety rail ... users should exit loops as soon as they receive an error, so we'll never get here.
|
||||||
// However, it does not seem to make a perf difference, so we add it out of an abundance of caution.
|
// However, it does not seem to make a perf difference, so we add it out of an abundance of caution.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#ifndef SIMDJSON_CONDITIONAL_INCLUDE
|
#ifndef SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
#define SIMDJSON_GENERIC_ONDEMAND_ARRAY_ITERATOR_H
|
#define SIMDJSON_GENERIC_ONDEMAND_ARRAY_ITERATOR_H
|
||||||
|
#include <iterator>
|
||||||
#include "simdjson/generic/implementation_simdjson_result_base.h"
|
#include "simdjson/generic/implementation_simdjson_result_base.h"
|
||||||
#include "simdjson/generic/ondemand/base.h"
|
#include "simdjson/generic/ondemand/base.h"
|
||||||
#include "simdjson/generic/ondemand/value_iterator.h"
|
#include "simdjson/generic/ondemand/value_iterator.h"
|
||||||
@@ -17,11 +18,17 @@ namespace ondemand {
|
|||||||
*
|
*
|
||||||
* This is an input_iterator, meaning:
|
* This is an input_iterator, meaning:
|
||||||
* - It is forward-only
|
* - It is forward-only
|
||||||
* - * must be called exactly once per element.
|
* - * must be called at most once per element.
|
||||||
* - ++ must be called exactly once in between each * (*, ++, *, ++, * ...)
|
* - ++ must be called exactly once in between each * (*, ++, *, ++, * ...)
|
||||||
*/
|
*/
|
||||||
class array_iterator {
|
class array_iterator {
|
||||||
public:
|
public:
|
||||||
|
using iterator_category = std::input_iterator_tag;
|
||||||
|
using value_type = simdjson_result<value>;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using pointer = void;
|
||||||
|
using reference = value_type;
|
||||||
|
|
||||||
/** Create a new, invalid array iterator. */
|
/** Create a new, invalid array iterator. */
|
||||||
simdjson_inline array_iterator() noexcept = default;
|
simdjson_inline array_iterator() noexcept = default;
|
||||||
|
|
||||||
@@ -65,6 +72,9 @@ public:
|
|||||||
simdjson_warn_unused simdjson_inline bool at_end() const noexcept;
|
simdjson_warn_unused simdjson_inline bool at_end() const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#if SIMDJSON_DEVELOPMENT_CHECKS
|
||||||
|
bool has_been_referenced{false};
|
||||||
|
#endif
|
||||||
value_iterator iter{};
|
value_iterator iter{};
|
||||||
|
|
||||||
simdjson_inline array_iterator(const value_iterator &iter) noexcept;
|
simdjson_inline array_iterator(const value_iterator &iter) noexcept;
|
||||||
@@ -82,6 +92,12 @@ namespace simdjson {
|
|||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> {
|
struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> {
|
||||||
|
using iterator_category = std::input_iterator_tag;
|
||||||
|
using value_type = simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using pointer = void;
|
||||||
|
using reference = value_type;
|
||||||
|
|
||||||
simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::array_iterator &&value) noexcept; ///< @private
|
simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::array_iterator &&value) noexcept; ///< @private
|
||||||
simdjson_inline simdjson_result(error_code error) noexcept; ///< @private
|
simdjson_inline simdjson_result(error_code error) noexcept; ///< @private
|
||||||
simdjson_inline simdjson_result() noexcept = default;
|
simdjson_inline simdjson_result() noexcept = default;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
// Internal headers needed for ondemand generics.
|
// Internal headers needed for ondemand generics.
|
||||||
// All includes not under simdjson/generic/ondemand must be here!
|
// All includes not under simdjson/generic/ondemand must be here!
|
||||||
// Otherwise, amalgamation will fail.
|
// Otherwise, amalgamation will fail.
|
||||||
#include "simdjson/concepts.h"
|
|
||||||
#include "simdjson/dom/base.h" // for MINIMAL_DOCUMENT_CAPACITY
|
#include "simdjson/dom/base.h" // for MINIMAL_DOCUMENT_CAPACITY
|
||||||
#include "simdjson/implementation.h"
|
#include "simdjson/implementation.h"
|
||||||
#include "simdjson/padded_string.h"
|
#include "simdjson/padded_string.h"
|
||||||
|
|||||||
@@ -347,7 +347,22 @@ simdjson_inline simdjson_result<value> document::at_path(std::string_view json_p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
simdjson_inline simdjson_result<std::vector<value>> document::at_path_with_wildcard(std::string_view json_path) noexcept {
|
||||||
|
rewind(); // Rewind the document each time at_path_with_wildcard is called
|
||||||
|
if (json_path.empty()) {
|
||||||
|
return INVALID_JSON_POINTER;
|
||||||
|
}
|
||||||
|
json_type t;
|
||||||
|
SIMDJSON_TRY(type().get(t));
|
||||||
|
switch (t) {
|
||||||
|
case json_type::array:
|
||||||
|
return (*this).get_array().at_path_with_wildcard(json_path);
|
||||||
|
case json_type::object:
|
||||||
|
return (*this).get_object().at_path_with_wildcard(json_path);
|
||||||
|
default:
|
||||||
|
return INVALID_JSON_POINTER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if SIMDJSON_SUPPORTS_CONCEPTS && SIMDJSON_STATIC_REFLECTION
|
#if SIMDJSON_SUPPORTS_CONCEPTS && SIMDJSON_STATIC_REFLECTION
|
||||||
|
|
||||||
@@ -672,6 +687,11 @@ simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjs
|
|||||||
return first.at_path(json_path);
|
return first.at_path(json_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::at_path_with_wildcard(std::string_view json_path) noexcept {
|
||||||
|
if (error()) { return error(); }
|
||||||
|
return first.at_path_with_wildcard(json_path);
|
||||||
|
}
|
||||||
|
|
||||||
#if SIMDJSON_STATIC_REFLECTION
|
#if SIMDJSON_STATIC_REFLECTION
|
||||||
template<constevalutil::fixed_string... FieldNames, typename T>
|
template<constevalutil::fixed_string... FieldNames, typename T>
|
||||||
requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
|
requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
|
||||||
@@ -766,6 +786,7 @@ simdjson_inline simdjson_result<number> document_reference::get_number() noexcep
|
|||||||
simdjson_inline simdjson_result<std::string_view> document_reference::raw_json_token() noexcept { return doc->raw_json_token(); }
|
simdjson_inline simdjson_result<std::string_view> document_reference::raw_json_token() noexcept { return doc->raw_json_token(); }
|
||||||
simdjson_inline simdjson_result<value> document_reference::at_pointer(std::string_view json_pointer) noexcept { return doc->at_pointer(json_pointer); }
|
simdjson_inline simdjson_result<value> document_reference::at_pointer(std::string_view json_pointer) noexcept { return doc->at_pointer(json_pointer); }
|
||||||
simdjson_inline simdjson_result<value> document_reference::at_path(std::string_view json_path) noexcept { return doc->at_path(json_path); }
|
simdjson_inline simdjson_result<value> document_reference::at_path(std::string_view json_path) noexcept { return doc->at_path(json_path); }
|
||||||
|
simdjson_inline simdjson_result<std::vector<value>> document_reference::at_path_with_wildcard(std::string_view json_path) noexcept { return doc->at_path_with_wildcard(json_path); }
|
||||||
simdjson_inline simdjson_result<std::string_view> document_reference::raw_json() noexcept { return doc->raw_json();}
|
simdjson_inline simdjson_result<std::string_view> document_reference::raw_json() noexcept { return doc->raw_json();}
|
||||||
simdjson_inline document_reference::operator document&() const noexcept { return *doc; }
|
simdjson_inline document_reference::operator document&() const noexcept { return *doc; }
|
||||||
#if SIMDJSON_SUPPORTS_CONCEPTS && SIMDJSON_STATIC_REFLECTION
|
#if SIMDJSON_SUPPORTS_CONCEPTS && SIMDJSON_STATIC_REFLECTION
|
||||||
@@ -1022,6 +1043,12 @@ simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjs
|
|||||||
}
|
}
|
||||||
return first.at_path(json_path);
|
return first.at_path(json_path);
|
||||||
}
|
}
|
||||||
|
simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::at_path_with_wildcard(std::string_view json_path) noexcept {
|
||||||
|
if (error()) {
|
||||||
|
return error();
|
||||||
|
}
|
||||||
|
return first.at_path_with_wildcard(json_path);
|
||||||
|
}
|
||||||
#if SIMDJSON_STATIC_REFLECTION
|
#if SIMDJSON_STATIC_REFLECTION
|
||||||
template<constevalutil::fixed_string... FieldNames, typename T>
|
template<constevalutil::fixed_string... FieldNames, typename T>
|
||||||
requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
|
requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "simdjson/generic/ondemand/json_iterator.h"
|
#include "simdjson/generic/ondemand/json_iterator.h"
|
||||||
#include "simdjson/generic/ondemand/deserialize.h"
|
#include "simdjson/generic/ondemand/deserialize.h"
|
||||||
#include "simdjson/generic/ondemand/value.h"
|
#include "simdjson/generic/ondemand/value.h"
|
||||||
|
#include <vector>
|
||||||
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
|
|
||||||
|
|
||||||
@@ -402,7 +403,9 @@ public:
|
|||||||
simdjson_inline simdjson_result<array_iterator> end() & noexcept;
|
simdjson_inline simdjson_result<array_iterator> end() & noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up a field by name on an object (order-sensitive).
|
* Look up a field by name on an object (order-sensitive). By order-sensitive, we mean that
|
||||||
|
* fields must be accessed in the order they appear in the JSON text (although you can
|
||||||
|
* skip fields). See find_field_unordered() and operator[] for an order-insensitive version.
|
||||||
*
|
*
|
||||||
* The following code reads z, then y, then x, and thus will not retrieve x or y if fed the
|
* The following code reads z, then y, then x, and thus will not retrieve x or y if fed the
|
||||||
* JSON `{ "x": 1, "y": 2, "z": 3 }`:
|
* JSON `{ "x": 1, "y": 2, "z": 3 }`:
|
||||||
@@ -446,7 +449,8 @@ public:
|
|||||||
* missing case has a non-cache-friendly bump and lots of extra scanning, especially if the object
|
* missing case has a non-cache-friendly bump and lots of extra scanning, especially if the object
|
||||||
* in question is large. The fact that the extra code is there also bumps the executable size.
|
* in question is large. The fact that the extra code is there also bumps the executable size.
|
||||||
*
|
*
|
||||||
* It is the default, however, because it would be highly surprising (and hard to debug) if the
|
* We default operator[] on find_field_unordered() for convenience.
|
||||||
|
* It is the default because it would be highly surprising (and hard to debug) if the
|
||||||
* default behavior failed to look up a field just because it was in the wrong order--and many
|
* default behavior failed to look up a field just because it was in the wrong order--and many
|
||||||
* APIs assume this. Therefore, you must be explicit if you want to treat objects as out of order.
|
* APIs assume this. Therefore, you must be explicit if you want to treat objects as out of order.
|
||||||
*
|
*
|
||||||
@@ -719,6 +723,23 @@ public:
|
|||||||
*/
|
*/
|
||||||
simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
|
simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all values matching the given JSONPath expression with wildcard support.
|
||||||
|
*
|
||||||
|
* Supports wildcard patterns like "$.array[*]" or "$.object.*" to match multiple elements.
|
||||||
|
*
|
||||||
|
* This method materializes all matching values into a vector.
|
||||||
|
* The document will be consumed after this call.
|
||||||
|
*
|
||||||
|
* @param json_path JSONPath expression with wildcards
|
||||||
|
* @return Vector of values matching the wildcard pattern, or:
|
||||||
|
* - INVALID_JSON_POINTER if the JSONPath cannot be parsed
|
||||||
|
* - NO_SUCH_FIELD if a field does not exist
|
||||||
|
* - INDEX_OUT_OF_BOUNDS if an array index is out of bounds
|
||||||
|
* - INCORRECT_TYPE if path traversal encounters wrong type
|
||||||
|
*/
|
||||||
|
simdjson_inline simdjson_result<std::vector<value>> at_path_with_wildcard(std::string_view json_path) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consumes the document and returns a string_view instance corresponding to the
|
* Consumes the document and returns a string_view instance corresponding to the
|
||||||
* document as represented in JSON. It points inside the original byte array containing
|
* document as represented in JSON. It points inside the original byte array containing
|
||||||
@@ -936,6 +957,7 @@ public:
|
|||||||
simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
|
simdjson_inline simdjson_result<std::string_view> raw_json_token() noexcept;
|
||||||
simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
|
simdjson_inline simdjson_result<value> at_pointer(std::string_view json_pointer) noexcept;
|
||||||
simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
|
simdjson_inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
|
||||||
|
simdjson_inline simdjson_result<std::vector<value>> at_path_with_wildcard(std::string_view json_path) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
document *doc{nullptr};
|
document *doc{nullptr};
|
||||||
@@ -1019,6 +1041,7 @@ public:
|
|||||||
|
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
|
||||||
|
simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> at_path_with_wildcard(std::string_view json_path) noexcept;
|
||||||
#if SIMDJSON_STATIC_REFLECTION
|
#if SIMDJSON_STATIC_REFLECTION
|
||||||
template<constevalutil::fixed_string... FieldNames, typename T>
|
template<constevalutil::fixed_string... FieldNames, typename T>
|
||||||
requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
|
requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
|
||||||
@@ -1101,6 +1124,7 @@ public:
|
|||||||
|
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
|
||||||
|
simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> at_path_with_wildcard(std::string_view json_path) noexcept;
|
||||||
#if SIMDJSON_STATIC_REFLECTION
|
#if SIMDJSON_STATIC_REFLECTION
|
||||||
template<constevalutil::fixed_string... FieldNames, typename T>
|
template<constevalutil::fixed_string... FieldNames, typename T>
|
||||||
requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
|
requires(std::is_class_v<T> && (sizeof...(FieldNames) > 0))
|
||||||
|
|||||||
@@ -215,11 +215,10 @@ simdjson_inline void json_iterator::assert_more_tokens(uint32_t required_tokens)
|
|||||||
}
|
}
|
||||||
|
|
||||||
simdjson_inline void json_iterator::assert_valid_position(token_position position) const noexcept {
|
simdjson_inline void json_iterator::assert_valid_position(token_position position) const noexcept {
|
||||||
|
(void)position; // Suppress unused parameter warning
|
||||||
#ifndef SIMDJSON_CLANG_VISUAL_STUDIO
|
#ifndef SIMDJSON_CLANG_VISUAL_STUDIO
|
||||||
SIMDJSON_ASSUME( position >= &parser->implementation->structural_indexes[0] );
|
SIMDJSON_ASSUME( position >= &parser->implementation->structural_indexes[0] );
|
||||||
SIMDJSON_ASSUME( position < &parser->implementation->structural_indexes[parser->implementation->n_structural_indexes] );
|
SIMDJSON_ASSUME( position < &parser->implementation->structural_indexes[parser->implementation->n_structural_indexes] );
|
||||||
#else
|
|
||||||
(void)position; // Suppress unused parameter warning
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,17 +357,25 @@ simdjson_inline token_position json_iterator::position() const noexcept {
|
|||||||
simdjson_inline simdjson_result<std::string_view> json_iterator::unescape(raw_json_string in, bool allow_replacement) noexcept {
|
simdjson_inline simdjson_result<std::string_view> json_iterator::unescape(raw_json_string in, bool allow_replacement) noexcept {
|
||||||
#if SIMDJSON_DEVELOPMENT_CHECKS
|
#if SIMDJSON_DEVELOPMENT_CHECKS
|
||||||
auto result = parser->unescape(in, _string_buf_loc, allow_replacement);
|
auto result = parser->unescape(in, _string_buf_loc, allow_replacement);
|
||||||
|
#if !defined(SIMDJSON_VISUAL_STUDIO) && !defined(SIMDJSON_CLANG_VISUAL_STUDIO)
|
||||||
|
// Under Visual Studio, the next SIMDJSON_ASSUME fails with: the argument
|
||||||
|
// has side effects that will be discarded.
|
||||||
SIMDJSON_ASSUME(!parser->string_buffer_overflow(_string_buf_loc));
|
SIMDJSON_ASSUME(!parser->string_buffer_overflow(_string_buf_loc));
|
||||||
|
#endif // !defined(SIMDJSON_VISUAL_STUDIO) && !defined(SIMDJSON_CLANG_VISUAL_STUDIO)
|
||||||
return result;
|
return result;
|
||||||
#else
|
#else
|
||||||
return parser->unescape(in, _string_buf_loc, allow_replacement);
|
return parser->unescape_maybe(in, _string_buf_loc, allow_replacement);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
simdjson_inline simdjson_result<std::string_view> json_iterator::unescape_wobbly(raw_json_string in) noexcept {
|
simdjson_inline simdjson_result<std::string_view> json_iterator::unescape_wobbly(raw_json_string in) noexcept {
|
||||||
#if SIMDJSON_DEVELOPMENT_CHECKS
|
#if SIMDJSON_DEVELOPMENT_CHECKS
|
||||||
auto result = parser->unescape_wobbly(in, _string_buf_loc);
|
auto result = parser->unescape_wobbly(in, _string_buf_loc);
|
||||||
|
#if !defined(SIMDJSON_VISUAL_STUDIO) && !defined(SIMDJSON_CLANG_VISUAL_STUDIO)
|
||||||
|
// Under Visual Studio, the next SIMDJSON_ASSUME fails with: the argument
|
||||||
|
// has side effects that will be discarded.
|
||||||
SIMDJSON_ASSUME(!parser->string_buffer_overflow(_string_buf_loc));
|
SIMDJSON_ASSUME(!parser->string_buffer_overflow(_string_buf_loc));
|
||||||
|
#endif // !defined(SIMDJSON_VISUAL_STUDIO) && !defined(SIMDJSON_CLANG_VISUAL_STUDIO)
|
||||||
return result;
|
return result;
|
||||||
#else
|
#else
|
||||||
return parser->unescape_wobbly(in, _string_buf_loc);
|
return parser->unescape_wobbly(in, _string_buf_loc);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "simdjson/generic/ondemand/raw_json_string.h"
|
#include "simdjson/generic/ondemand/raw_json_string.h"
|
||||||
#include "simdjson/generic/ondemand/json_iterator.h"
|
#include "simdjson/generic/ondemand/json_iterator.h"
|
||||||
#include "simdjson/generic/ondemand/value-inl.h"
|
#include "simdjson/generic/ondemand/value-inl.h"
|
||||||
|
#include "simdjson/jsonpathutil.h"
|
||||||
#if SIMDJSON_STATIC_REFLECTION
|
#if SIMDJSON_STATIC_REFLECTION
|
||||||
#include "simdjson/generic/ondemand/json_string_builder.h" // for constevalutil::fixed_string
|
#include "simdjson/generic/ondemand/json_string_builder.h" // for constevalutil::fixed_string
|
||||||
#include <meta>
|
#include <meta>
|
||||||
@@ -176,6 +177,50 @@ inline simdjson_result<value> object::at_path(std::string_view json_path) noexce
|
|||||||
return at_pointer(json_pointer);
|
return at_pointer(json_pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline simdjson_result<std::vector<value>> object::at_path_with_wildcard(std::string_view json_path) noexcept {
|
||||||
|
std::vector<value> result;
|
||||||
|
|
||||||
|
auto result_pair = get_next_key_and_json_path(json_path);
|
||||||
|
std::string_view key = result_pair.first;
|
||||||
|
std::string_view remaining_path = result_pair.second;
|
||||||
|
// Handle when its the case for wildcard
|
||||||
|
if (key == "*") {
|
||||||
|
// Loop through each field in the object
|
||||||
|
for (auto field : *this) {
|
||||||
|
value val;
|
||||||
|
SIMDJSON_TRY(field.value().get(val));
|
||||||
|
|
||||||
|
if (remaining_path.empty()) {
|
||||||
|
result.push_back(std::move(val));
|
||||||
|
} else {
|
||||||
|
auto nested_result = val.at_path_with_wildcard(remaining_path);
|
||||||
|
|
||||||
|
if (nested_result.error()) {
|
||||||
|
return nested_result.error();
|
||||||
|
}
|
||||||
|
// Extract and append all nested matches to our result
|
||||||
|
std::vector<value> nested_vec;
|
||||||
|
SIMDJSON_TRY(std::move(nested_result).get(nested_vec));
|
||||||
|
|
||||||
|
result.insert(result.end(),
|
||||||
|
std::make_move_iterator(nested_vec.begin()),
|
||||||
|
std::make_move_iterator(nested_vec.end()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
value val;
|
||||||
|
SIMDJSON_TRY(find_field(key).get(val));
|
||||||
|
|
||||||
|
if (remaining_path.empty()) {
|
||||||
|
result.push_back(std::move(val));
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
return val.at_path_with_wildcard(remaining_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
simdjson_inline simdjson_result<size_t> object::count_fields() & noexcept {
|
simdjson_inline simdjson_result<size_t> object::count_fields() & noexcept {
|
||||||
size_t count{0};
|
size_t count{0};
|
||||||
// Important: we do not consume any of the values.
|
// Important: we do not consume any of the values.
|
||||||
@@ -302,6 +347,11 @@ simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjs
|
|||||||
return first.at_path(json_path);
|
return first.at_path(json_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object>::at_path_with_wildcard(std::string_view json_path) noexcept {
|
||||||
|
if (error()) { return error(); }
|
||||||
|
return first.at_path_with_wildcard(json_path);
|
||||||
|
}
|
||||||
|
|
||||||
inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object>::reset() noexcept {
|
inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object>::reset() noexcept {
|
||||||
if (error()) { return error(); }
|
if (error()) { return error(); }
|
||||||
return first.reset();
|
return first.reset();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "simdjson/generic/ondemand/base.h"
|
#include "simdjson/generic/ondemand/base.h"
|
||||||
#include "simdjson/generic/implementation_simdjson_result_base.h"
|
#include "simdjson/generic/implementation_simdjson_result_base.h"
|
||||||
#include "simdjson/generic/ondemand/value_iterator.h"
|
#include "simdjson/generic/ondemand/value_iterator.h"
|
||||||
|
#include <vector>
|
||||||
#if SIMDJSON_STATIC_REFLECTION && SIMDJSON_SUPPORTS_CONCEPTS
|
#if SIMDJSON_STATIC_REFLECTION && SIMDJSON_SUPPORTS_CONCEPTS
|
||||||
#include "simdjson/generic/ondemand/json_string_builder.h" // for constevalutil::fixed_string
|
#include "simdjson/generic/ondemand/json_string_builder.h" // for constevalutil::fixed_string
|
||||||
#endif
|
#endif
|
||||||
@@ -26,10 +27,19 @@ public:
|
|||||||
*/
|
*/
|
||||||
simdjson_inline object() noexcept = default;
|
simdjson_inline object() noexcept = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an iterator to the start of the object. We recommend using a range-based for loop.
|
||||||
|
*
|
||||||
|
* Using the iterator directly is also possible but error-prone and discouraged. In particular,
|
||||||
|
* you must dereference the iterator exactly once per iteration (before calling '++').
|
||||||
|
* Doing otherwise is unsafe and may lead to errors. You are responsible for ensuring
|
||||||
|
*/
|
||||||
simdjson_inline simdjson_result<object_iterator> begin() noexcept;
|
simdjson_inline simdjson_result<object_iterator> begin() noexcept;
|
||||||
simdjson_inline simdjson_result<object_iterator> end() noexcept;
|
simdjson_inline simdjson_result<object_iterator> end() noexcept;
|
||||||
/**
|
/**
|
||||||
* Look up a field by name on an object (order-sensitive).
|
* Look up a field by name on an object (order-sensitive). By order-sensitive, we mean that
|
||||||
|
* fields must be accessed in the order they appear in the JSON text (although you can
|
||||||
|
* skip fields). See find_field_unordered() and operator[] for an order-insensitive version.
|
||||||
*
|
*
|
||||||
* The following code reads z, then y, then x, and thus will not retrieve x or y if fed the
|
* The following code reads z, then y, then x, and thus will not retrieve x or y if fed the
|
||||||
* JSON `{ "x": 1, "y": 2, "z": 3 }`:
|
* JSON `{ "x": 1, "y": 2, "z": 3 }`:
|
||||||
@@ -77,7 +87,8 @@ public:
|
|||||||
* missing case has a non-cache-friendly bump and lots of extra scanning, especially if the object
|
* missing case has a non-cache-friendly bump and lots of extra scanning, especially if the object
|
||||||
* in question is large. The fact that the extra code is there also bumps the executable size.
|
* in question is large. The fact that the extra code is there also bumps the executable size.
|
||||||
*
|
*
|
||||||
* It is the default, however, because it would be highly surprising (and hard to debug) if the
|
* We default operator[] on find_field_unordered() for convenience.
|
||||||
|
* It is the default because it would be highly surprising (and hard to debug) if the
|
||||||
* default behavior failed to look up a field just because it was in the wrong order--and many
|
* default behavior failed to look up a field just because it was in the wrong order--and many
|
||||||
* APIs assume this. Therefore, you must be explicit if you want to treat objects as out of order.
|
* APIs assume this. Therefore, you must be explicit if you want to treat objects as out of order.
|
||||||
*
|
*
|
||||||
@@ -160,6 +171,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
|
inline simdjson_result<value> at_path(std::string_view json_path) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all values matching the given JSONPath expression with wildcard support.
|
||||||
|
* Supports wildcard patterns like ".*" to match all object fields.
|
||||||
|
*
|
||||||
|
* @param json_path JSONPath expression with wildcards
|
||||||
|
* @return Vector of values matching the wildcard pattern
|
||||||
|
*/
|
||||||
|
inline simdjson_result<std::vector<value>> at_path_with_wildcard(std::string_view json_path) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the iterator so that we are pointing back at the
|
* Reset the iterator so that we are pointing back at the
|
||||||
* beginning of the object. You should still consume values only once even if you
|
* beginning of the object. You should still consume values only once even if you
|
||||||
@@ -308,6 +328,7 @@ public:
|
|||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) && noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> operator[](std::string_view key) && noexcept;
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
|
||||||
|
simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> at_path_with_wildcard(std::string_view json_path) noexcept;
|
||||||
inline simdjson_result<bool> reset() noexcept;
|
inline simdjson_result<bool> reset() noexcept;
|
||||||
inline simdjson_result<bool> is_empty() noexcept;
|
inline simdjson_result<bool> is_empty() noexcept;
|
||||||
inline simdjson_result<size_t> count_fields() & noexcept;
|
inline simdjson_result<size_t> count_fields() & noexcept;
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ simdjson_inline object_iterator::object_iterator(const value_iterator &_iter) no
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
simdjson_inline simdjson_result<field> object_iterator::operator*() noexcept {
|
simdjson_inline simdjson_result<field> object_iterator::operator*() noexcept {
|
||||||
|
#if SIMDJSON_DEVELOPMENT_CHECKS
|
||||||
|
// We must call * once per iteration.
|
||||||
|
SIMDJSON_ASSUME(!has_been_referenced);
|
||||||
|
has_been_referenced = true;
|
||||||
|
#endif
|
||||||
error_code error = iter.error();
|
error_code error = iter.error();
|
||||||
if (error) { iter.abandon(); return error; }
|
if (error) { iter.abandon(); return error; }
|
||||||
auto result = field::start(iter);
|
auto result = field::start(iter);
|
||||||
@@ -39,6 +44,11 @@ simdjson_inline bool object_iterator::operator!=(const object_iterator &) const
|
|||||||
SIMDJSON_PUSH_DISABLE_WARNINGS
|
SIMDJSON_PUSH_DISABLE_WARNINGS
|
||||||
SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING
|
SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING
|
||||||
simdjson_inline object_iterator &object_iterator::operator++() noexcept {
|
simdjson_inline object_iterator &object_iterator::operator++() noexcept {
|
||||||
|
#if SIMDJSON_DEVELOPMENT_CHECKS
|
||||||
|
// Before calling ++, we must have called *.
|
||||||
|
SIMDJSON_ASSUME(has_been_referenced);
|
||||||
|
has_been_referenced = false;
|
||||||
|
#endif
|
||||||
// TODO this is a safety rail ... users should exit loops as soon as they receive an error.
|
// TODO this is a safety rail ... users should exit loops as soon as they receive an error.
|
||||||
// Nonetheless, let's see if performance is OK with this if statement--the compiler may give it to us for free.
|
// Nonetheless, let's see if performance is OK with this if statement--the compiler may give it to us for free.
|
||||||
if (!iter.is_open()) { return *this; } // Iterator will be released if there is an error
|
if (!iter.is_open()) { return *this; } // Iterator will be released if there is an error
|
||||||
|
|||||||
@@ -32,9 +32,14 @@ public:
|
|||||||
// Assumes it's being compared with the end. true if depth >= iter->depth.
|
// Assumes it's being compared with the end. true if depth >= iter->depth.
|
||||||
simdjson_inline bool operator!=(const object_iterator &) const noexcept;
|
simdjson_inline bool operator!=(const object_iterator &) const noexcept;
|
||||||
// Checks for ']' and ','
|
// Checks for ']' and ','
|
||||||
|
// YOU MUST NOT CALL THIS IF operator* YIELDED AN ERROR.
|
||||||
|
// YOU MUST NOT CALL THIS WITHOUT A CORRESPONDING operator* CALL.
|
||||||
simdjson_inline object_iterator &operator++() noexcept;
|
simdjson_inline object_iterator &operator++() noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#if SIMDJSON_DEVELOPMENT_CHECKS
|
||||||
|
bool has_been_referenced{false};
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* The underlying JSON iterator.
|
* The underlying JSON iterator.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -179,6 +179,20 @@ simdjson_inline void parser::set_max_capacity(size_t max_capacity) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
simdjson_inline simdjson_warn_unused simdjson_result<std::string_view> parser::unescape_maybe(raw_json_string in, uint8_t *&dst, bool allow_replacement) const noexcept {
|
||||||
|
std::pair<const uint8_t *, bool> result = implementation->parse_string_if_needed(in.buf, dst, allow_replacement);
|
||||||
|
const uint8_t *end = result.first;
|
||||||
|
bool copied = result.second;
|
||||||
|
if (!end) { return STRING_ERROR; }
|
||||||
|
if(copied) {
|
||||||
|
std::string_view strresult(reinterpret_cast<const char *>(dst), end-dst);
|
||||||
|
dst = const_cast<uint8_t *>(end);
|
||||||
|
return strresult;
|
||||||
|
}
|
||||||
|
// fast path, no copy was made!!!
|
||||||
|
return std::string_view(reinterpret_cast<const char *>(in.buf), end-in.buf);
|
||||||
|
}
|
||||||
|
|
||||||
simdjson_inline simdjson_warn_unused simdjson_result<std::string_view> parser::unescape(raw_json_string in, uint8_t *&dst, bool allow_replacement) const noexcept {
|
simdjson_inline simdjson_warn_unused simdjson_result<std::string_view> parser::unescape(raw_json_string in, uint8_t *&dst, bool allow_replacement) const noexcept {
|
||||||
uint8_t *end = implementation->parse_string(in.buf, dst, allow_replacement);
|
uint8_t *end = implementation->parse_string(in.buf, dst, allow_replacement);
|
||||||
if (!end) { return STRING_ERROR; }
|
if (!end) { return STRING_ERROR; }
|
||||||
|
|||||||
@@ -334,6 +334,32 @@ public:
|
|||||||
*/
|
*/
|
||||||
simdjson_inline simdjson_result<std::string_view> unescape(raw_json_string in, uint8_t *&dst, bool allow_replacement = false) const noexcept;
|
simdjson_inline simdjson_result<std::string_view> unescape(raw_json_string in, uint8_t *&dst, bool allow_replacement = false) const noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unescape this JSON string, replacing \\ with \, \n with newline, etc. to a user-provided buffer if
|
||||||
|
* needed. If no escaping is done, the string is returned as is and dst is not not changed.
|
||||||
|
* The result must be valid UTF-8.
|
||||||
|
* The provided pointer is advanced to the end of the string by reference if a copy is needed,
|
||||||
|
* and a string_view instance
|
||||||
|
* is returned. You can ensure that your buffer is large enough by allocating a block of memory at least
|
||||||
|
* as large as the input JSON plus SIMDJSON_PADDING and then unescape all strings to this one buffer.
|
||||||
|
*
|
||||||
|
* This unescape_maybe function is a low-level function. If you want a more user-friendly approach, you should
|
||||||
|
* avoid raw_json_string instances (e.g., by calling unescaped_key() instead of key() or get_string()
|
||||||
|
* instead of get_raw_json_string()).
|
||||||
|
*
|
||||||
|
* ## IMPORTANT: string_view lifetime
|
||||||
|
*
|
||||||
|
* The string_view is only valid as long as the bytes in dst.
|
||||||
|
*
|
||||||
|
* @param raw_json_string input
|
||||||
|
* @param dst A pointer to a buffer at least large enough to write this string as well as
|
||||||
|
* an additional SIMDJSON_PADDING bytes.
|
||||||
|
* @param allow_replacement Whether we allow a replacement if the input string contains unmatched surrogate pairs.
|
||||||
|
* @return A string_view pointing at the unescaped string in dst
|
||||||
|
* @error STRING_ERROR if escapes are incorrect.
|
||||||
|
*/
|
||||||
|
simdjson_inline simdjson_result<std::string_view> unescape_maybe(raw_json_string in, uint8_t *&dst, bool allow_replacement = false) const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unescape this JSON string, replacing \\ with \, \n with newline, etc. to a user-provided buffer.
|
* Unescape this JSON string, replacing \\ with \, \n with newline, etc. to a user-provided buffer.
|
||||||
* The result may not be valid UTF-8. See https://simonsapin.github.io/wtf-8/
|
* The result may not be valid UTF-8. See https://simonsapin.github.io/wtf-8/
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "simdjson/generic/ondemand/serialization.h"
|
#include "simdjson/generic/ondemand/serialization.h"
|
||||||
#include "simdjson/generic/ondemand/value.h"
|
#include "simdjson/generic/ondemand/value.h"
|
||||||
#if SIMDJSON_STATIC_REFLECTION
|
#if SIMDJSON_STATIC_REFLECTION
|
||||||
#include "simdjson/generic/ondemand/json_builder.h"
|
#include "simdjson/generic/builder/json_builder.h"
|
||||||
#endif
|
#endif
|
||||||
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
|
|
||||||
|
|||||||
@@ -296,6 +296,19 @@ simdjson_inline simdjson_result<value> value::at_path(std::string_view json_path
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline simdjson_result<std::vector<value>> value::at_path_with_wildcard(std::string_view json_path) noexcept {
|
||||||
|
json_type t;
|
||||||
|
SIMDJSON_TRY(type().get(t));
|
||||||
|
switch (t) {
|
||||||
|
case json_type::array:
|
||||||
|
return (*this).get_array().at_path_with_wildcard(json_path);
|
||||||
|
case json_type::object:
|
||||||
|
return (*this).get_object().at_path_with_wildcard(json_path);
|
||||||
|
default:
|
||||||
|
return INVALID_JSON_POINTER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ondemand
|
} // namespace ondemand
|
||||||
} // namespace SIMDJSON_IMPLEMENTATION
|
} // namespace SIMDJSON_IMPLEMENTATION
|
||||||
} // namespace simdjson
|
} // namespace simdjson
|
||||||
@@ -546,6 +559,14 @@ simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjs
|
|||||||
return first.at_path(json_path);
|
return first.at_path(json_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::at_path_with_wildcard(
|
||||||
|
std::string_view json_path) noexcept {
|
||||||
|
if (error()) {
|
||||||
|
return error();
|
||||||
|
}
|
||||||
|
return first.at_path_with_wildcard(json_path);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace simdjson
|
} // namespace simdjson
|
||||||
|
|
||||||
#endif // SIMDJSON_GENERIC_ONDEMAND_VALUE_INL_H
|
#endif // SIMDJSON_GENERIC_ONDEMAND_VALUE_INL_H
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "simdjson/generic/implementation_simdjson_result_base.h"
|
#include "simdjson/generic/implementation_simdjson_result_base.h"
|
||||||
#include "simdjson/generic/ondemand/value_iterator.h"
|
#include "simdjson/generic/ondemand/value_iterator.h"
|
||||||
#include "simdjson/generic/ondemand/deserialize.h"
|
#include "simdjson/generic/ondemand/deserialize.h"
|
||||||
|
#include <vector>
|
||||||
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -394,7 +395,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
simdjson_inline simdjson_result<value> at(size_t index) noexcept;
|
simdjson_inline simdjson_result<value> at(size_t index) noexcept;
|
||||||
/**
|
/**
|
||||||
* Look up a field by name on an object (order-sensitive).
|
* Look up a field by name on an object (order-sensitive). By order-sensitive, we mean that
|
||||||
|
* fields must be accessed in the order they appear in the JSON text (although you can
|
||||||
|
* skip fields). See find_field_unordered() and operator[] for an order-insensitive version.
|
||||||
*
|
*
|
||||||
* The following code reads z, then y, then x, and thus will not retrieve x or y if fed the
|
* The following code reads z, then y, then x, and thus will not retrieve x or y if fed the
|
||||||
* JSON `{ "x": 1, "y": 2, "z": 3 }`:
|
* JSON `{ "x": 1, "y": 2, "z": 3 }`:
|
||||||
@@ -428,7 +431,8 @@ public:
|
|||||||
* missing case has a non-cache-friendly bump and lots of extra scanning, especially if the object
|
* missing case has a non-cache-friendly bump and lots of extra scanning, especially if the object
|
||||||
* in question is large. The fact that the extra code is there also bumps the executable size.
|
* in question is large. The fact that the extra code is there also bumps the executable size.
|
||||||
*
|
*
|
||||||
* It is the default, however, because it would be highly surprising (and hard to debug) if the
|
* We default operator[] on find_field_unordered() for convenience.
|
||||||
|
* It is the default because it would be highly surprising (and hard to debug) if the
|
||||||
* default behavior failed to look up a field just because it was in the wrong order--and many
|
* default behavior failed to look up a field just because it was in the wrong order--and many
|
||||||
* APIs assume this. Therefore, you must be explicit if you want to treat objects as out of order.
|
* APIs assume this. Therefore, you must be explicit if you want to treat objects as out of order.
|
||||||
*
|
*
|
||||||
@@ -671,6 +675,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
simdjson_inline simdjson_result<value> at_path(std::string_view at_path) noexcept;
|
simdjson_inline simdjson_result<value> at_path(std::string_view at_path) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all values matching the given JSONPath expression with wildcard support.
|
||||||
|
* Supports wildcard character (*) for arrays or ".*" for objects.
|
||||||
|
*
|
||||||
|
* @param json_path JSONPath expression with wildcards
|
||||||
|
* @return Vector of values matching the wildcard pattern
|
||||||
|
*/
|
||||||
|
simdjson_inline simdjson_result<std::vector<value>> at_path_with_wildcard(std::string_view json_path) noexcept;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@@ -767,7 +779,9 @@ public:
|
|||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> end() & noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> end() & noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up a field by name on an object (order-sensitive).
|
* Look up a field by name on an object (order-sensitive). By order-sensitive, we mean that
|
||||||
|
* fields must be accessed in the order they appear in the JSON text (although you can
|
||||||
|
* skip fields). See find_field_unordered() and operator[] for an order-insensitive version.
|
||||||
*
|
*
|
||||||
* The following code reads z, then y, then x, and thus will not retrieve x or y if fed the
|
* The following code reads z, then y, then x, and thus will not retrieve x or y if fed the
|
||||||
* JSON `{ "x": 1, "y": 2, "z": 3 }`:
|
* JSON `{ "x": 1, "y": 2, "z": 3 }`:
|
||||||
@@ -799,7 +813,8 @@ public:
|
|||||||
* missing case has a non-cache-friendly bump and lots of extra scanning, especially if the object
|
* missing case has a non-cache-friendly bump and lots of extra scanning, especially if the object
|
||||||
* in question is large. The fact that the extra code is there also bumps the executable size.
|
* in question is large. The fact that the extra code is there also bumps the executable size.
|
||||||
*
|
*
|
||||||
* It is the default, however, because it would be highly surprising (and hard to debug) if the
|
* We default operator[] on find_field_unordered() for convenience.
|
||||||
|
* It is the default because it would be highly surprising (and hard to debug) if the
|
||||||
* default behavior failed to look up a field just because it was in the wrong order--and many
|
* default behavior failed to look up a field just because it was in the wrong order--and many
|
||||||
* APIs assume this. Therefore, you must be explicit if you want to treat objects as out of order.
|
* APIs assume this. Therefore, you must be explicit if you want to treat objects as out of order.
|
||||||
*
|
*
|
||||||
@@ -858,6 +873,7 @@ public:
|
|||||||
simdjson_inline simdjson_result<int32_t> current_depth() const noexcept;
|
simdjson_inline simdjson_result<int32_t> current_depth() const noexcept;
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_pointer(std::string_view json_pointer) noexcept;
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> at_path(std::string_view json_path) noexcept;
|
||||||
|
simdjson_inline simdjson_result<std::vector<SIMDJSON_IMPLEMENTATION::ondemand::value>> at_path_with_wildcard(std::string_view json_path) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace simdjson
|
} // namespace simdjson
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ simdjson_warn_unused simdjson_inline error_code value_iterator::end_container()
|
|||||||
|
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<bool> value_iterator::has_next_field() noexcept {
|
simdjson_warn_unused simdjson_inline simdjson_result<bool> value_iterator::has_next_field() noexcept {
|
||||||
assert_at_next();
|
assert_at_next();
|
||||||
|
|
||||||
// It's illegal to call this unless there are more tokens: anything that ends in } or ] is
|
// It's illegal to call this unless there are more tokens: anything that ends in } or ] is
|
||||||
// obligated to verify there are more tokens if they are not the top level.
|
// obligated to verify there are more tokens if they are not the top level.
|
||||||
switch (*_json_iter->return_current_and_advance()) {
|
switch (*_json_iter->return_current_and_advance()) {
|
||||||
@@ -967,6 +966,9 @@ simdjson_inline bool value_iterator::is_at_key() const noexcept {
|
|||||||
// Keys are at the same depth as the object.
|
// Keys are at the same depth as the object.
|
||||||
// Note here that we could be safer and check that we are within an object,
|
// Note here that we could be safer and check that we are within an object,
|
||||||
// but we do not.
|
// but we do not.
|
||||||
|
//
|
||||||
|
// As long as we are at the object's depth, in a valid document,
|
||||||
|
// we will only ever be at { , : or the actual string key: ".
|
||||||
return _depth == _json_iter->_depth && *_json_iter->peek() == '"';
|
return _depth == _json_iter->_depth && *_json_iter->peek() == '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -472,6 +472,7 @@ protected:
|
|||||||
|
|
||||||
friend class document;
|
friend class document;
|
||||||
friend class object;
|
friend class object;
|
||||||
|
friend class object_iterator;
|
||||||
friend class array;
|
friend class array;
|
||||||
friend class value;
|
friend class value;
|
||||||
friend class field;
|
friend class field;
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef SIMDJSON_HASWELL_BUILDER_H
|
||||||
|
#define SIMDJSON_HASWELL_BUILDER_H
|
||||||
|
|
||||||
|
#include "simdjson/haswell/begin.h"
|
||||||
|
#include "simdjson/generic/builder/amalgamated.h"
|
||||||
|
#include "simdjson/haswell/end.h"
|
||||||
|
|
||||||
|
#endif // SIMDJSON_HASWELL_BUILDER_H
|
||||||
@@ -17,6 +17,7 @@ using namespace simd;
|
|||||||
struct backslash_and_quote {
|
struct backslash_and_quote {
|
||||||
public:
|
public:
|
||||||
static constexpr uint32_t BYTES_PROCESSED = 32;
|
static constexpr uint32_t BYTES_PROCESSED = 32;
|
||||||
|
// We only copy if dst is non-null.
|
||||||
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
||||||
|
|
||||||
simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
|
simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
|
||||||
@@ -34,7 +35,9 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin
|
|||||||
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
|
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
|
||||||
simd8<uint8_t> v(src);
|
simd8<uint8_t> v(src);
|
||||||
// store to dest unconditionally - we can overwrite the bits we don't like later
|
// store to dest unconditionally - we can overwrite the bits we don't like later
|
||||||
v.store(dst);
|
if(dst != nullptr) {
|
||||||
|
v.store(dst);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
static_cast<uint32_t>((v == '\\').to_bitmask()), // bs_bits
|
static_cast<uint32_t>((v == '\\').to_bitmask()), // bs_bits
|
||||||
static_cast<uint32_t>((v == '"').to_bitmask()), // quote_bits
|
static_cast<uint32_t>((v == '"').to_bitmask()), // quote_bits
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef SIMDJSON_ICELAKE_BUILDER_H
|
||||||
|
#define SIMDJSON_ICELAKE_BUILDER_H
|
||||||
|
|
||||||
|
#include "simdjson/icelake/begin.h"
|
||||||
|
#include "simdjson/generic/builder/amalgamated.h"
|
||||||
|
#include "simdjson/icelake/end.h"
|
||||||
|
|
||||||
|
#endif // SIMDJSON_ICELAKE_BUILDER_H
|
||||||
@@ -17,6 +17,7 @@ using namespace simd;
|
|||||||
struct backslash_and_quote {
|
struct backslash_and_quote {
|
||||||
public:
|
public:
|
||||||
static constexpr uint32_t BYTES_PROCESSED = 64;
|
static constexpr uint32_t BYTES_PROCESSED = 64;
|
||||||
|
// We only copy if dst is non-null.
|
||||||
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
||||||
|
|
||||||
simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
|
simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
|
||||||
@@ -34,7 +35,9 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin
|
|||||||
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
|
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
|
||||||
simd8<uint8_t> v(src);
|
simd8<uint8_t> v(src);
|
||||||
// store to dest unconditionally - we can overwrite the bits we don't like later
|
// store to dest unconditionally - we can overwrite the bits we don't like later
|
||||||
v.store(dst);
|
if(dst != nullptr) {
|
||||||
|
v.store(dst);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
static_cast<uint64_t>(v == '\\'), // bs_bits
|
static_cast<uint64_t>(v == '\\'), // bs_bits
|
||||||
static_cast<uint64_t>(v == '"'), // quote_bits
|
static_cast<uint64_t>(v == '"'), // quote_bits
|
||||||
|
|||||||
@@ -113,15 +113,15 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SIMDJSON_IMPLEMENTATION_LASX
|
#ifndef SIMDJSON_IMPLEMENTATION_LASX
|
||||||
#define SIMDJSON_IMPLEMENTATION_LASX (SIMDJSON_IS_LOONGARCH64 && __loongarch_asx)
|
#define SIMDJSON_IMPLEMENTATION_LASX (SIMDJSON_IS_LSX)
|
||||||
#endif
|
#endif
|
||||||
#define SIMDJSON_CAN_ALWAYS_RUN_LASX (SIMDJSON_IMPLEMENTATION_LASX)
|
#define SIMDJSON_CAN_ALWAYS_RUN_LASX (SIMDJSON_IS_LASX)
|
||||||
|
|
||||||
#ifndef SIMDJSON_IMPLEMENTATION_LSX
|
#ifndef SIMDJSON_IMPLEMENTATION_LSX
|
||||||
#if SIMDJSON_CAN_ALWAYS_RUN_LASX
|
#if SIMDJSON_CAN_ALWAYS_RUN_LASX
|
||||||
#define SIMDJSON_IMPLEMENTATION_LSX 0
|
#define SIMDJSON_IMPLEMENTATION_LSX 0
|
||||||
#else
|
#else
|
||||||
#define SIMDJSON_IMPLEMENTATION_LSX (SIMDJSON_IS_LOONGARCH64 && __loongarch_sx)
|
#define SIMDJSON_IMPLEMENTATION_LSX (SIMDJSON_IS_LSX)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#define SIMDJSON_CAN_ALWAYS_RUN_LSX (SIMDJSON_IMPLEMENTATION_LSX)
|
#define SIMDJSON_CAN_ALWAYS_RUN_LSX (SIMDJSON_IMPLEMENTATION_LSX)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "simdjson/base.h"
|
#include "simdjson/base.h"
|
||||||
#include "simdjson/error.h"
|
#include "simdjson/error.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace simdjson {
|
namespace simdjson {
|
||||||
|
|
||||||
@@ -102,6 +103,24 @@ public:
|
|||||||
*/
|
*/
|
||||||
simdjson_warn_unused virtual error_code stage2_next(dom::document &doc) noexcept = 0;
|
simdjson_warn_unused virtual error_code stage2_next(dom::document &doc) noexcept = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unescape a valid UTF-8 string from src to dst, stopping at a final unescaped quote. There
|
||||||
|
* must be an unescaped quote terminating the string. It returns the final output
|
||||||
|
* position as pointer. In case of error (e.g., the string has bad escaped codes),
|
||||||
|
* then null_ptr is returned. If no escaping was required, then no copy is made.
|
||||||
|
* It is assumed that the output buffer is large
|
||||||
|
* enough to store the unescapedstring + SIMDJSON_PADDING bytes.
|
||||||
|
*
|
||||||
|
* Overridden by each implementation.
|
||||||
|
*
|
||||||
|
* @param str pointer to the beginning of a valid UTF-8 JSON string, must end with an unescaped quote.
|
||||||
|
* @param dst pointer to a destination buffer, it must point a region in memory of sufficient size.
|
||||||
|
* @param allow_replacement whether we allow a replacement character when the UTF-8 contains unmatched surrogate pairs.
|
||||||
|
* @return end of the of the written region (exclusive) or nullptr in case of error coupled with a Boolean telling you if a copy was made
|
||||||
|
*/
|
||||||
|
simdjson_warn_unused virtual std::pair<const uint8_t *,bool> parse_string_if_needed(const uint8_t *src, uint8_t *dst, bool allow_replacement) const noexcept = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unescape a valid UTF-8 string from src to dst, stopping at a final unescaped quote. There
|
* Unescape a valid UTF-8 string from src to dst, stopping at a final unescaped quote. There
|
||||||
* must be an unescaped quote terminating the string. It returns the final output
|
* must be an unescaped quote terminating the string. It returns the final output
|
||||||
|
|||||||
@@ -0,0 +1,161 @@
|
|||||||
|
#ifndef SIMDJSON_INTERNAL_FRACTURED_FORMATTER_H
|
||||||
|
#define SIMDJSON_INTERNAL_FRACTURED_FORMATTER_H
|
||||||
|
|
||||||
|
#include "simdjson/dom/serialization.h"
|
||||||
|
#include "simdjson/dom/fractured_json.h"
|
||||||
|
#include "simdjson/internal/json_structure_analyzer.h"
|
||||||
|
|
||||||
|
namespace simdjson {
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fractured JSON formatter using CRTP pattern.
|
||||||
|
*
|
||||||
|
* This formatter intelligently chooses between different layout modes
|
||||||
|
* (inline, compact multiline, table, expanded) based on pre-computed
|
||||||
|
* structure metrics.
|
||||||
|
*/
|
||||||
|
class fractured_formatter : public base_formatter<fractured_formatter> {
|
||||||
|
public:
|
||||||
|
explicit fractured_formatter(const fractured_json_options& opts = {});
|
||||||
|
|
||||||
|
/** CRTP hook: print newline (context-aware) */
|
||||||
|
simdjson_inline void print_newline();
|
||||||
|
|
||||||
|
/** CRTP hook: print indentation */
|
||||||
|
simdjson_inline void print_indents(size_t depth);
|
||||||
|
|
||||||
|
/** CRTP hook: print space (context-aware) */
|
||||||
|
simdjson_inline void print_space();
|
||||||
|
|
||||||
|
/** Set the current layout mode */
|
||||||
|
void set_layout_mode(layout_mode mode);
|
||||||
|
|
||||||
|
/** Get the current layout mode */
|
||||||
|
layout_mode get_layout_mode() const;
|
||||||
|
|
||||||
|
/** Set current depth for formatting decisions */
|
||||||
|
void set_depth(size_t depth);
|
||||||
|
|
||||||
|
/** Get current depth */
|
||||||
|
size_t get_depth() const;
|
||||||
|
|
||||||
|
/** Track current line length for compact multiline decisions */
|
||||||
|
void track_line_length(size_t chars);
|
||||||
|
|
||||||
|
/** Reset line length (after newline) */
|
||||||
|
void reset_line_length();
|
||||||
|
|
||||||
|
/** Get current line length */
|
||||||
|
size_t get_line_length() const;
|
||||||
|
|
||||||
|
/** Check if we should break to a new line in compact mode */
|
||||||
|
bool should_break_line(size_t upcoming_length) const;
|
||||||
|
|
||||||
|
/** Get the options */
|
||||||
|
const fractured_json_options& options() const;
|
||||||
|
|
||||||
|
// Table formatting support
|
||||||
|
/** Begin a table row */
|
||||||
|
void begin_table_row();
|
||||||
|
|
||||||
|
/** End a table row */
|
||||||
|
void end_table_row();
|
||||||
|
|
||||||
|
/** Set column widths for table alignment */
|
||||||
|
void set_column_widths(const std::vector<size_t>& widths);
|
||||||
|
|
||||||
|
/** Get current column index in table mode */
|
||||||
|
size_t get_column_index() const;
|
||||||
|
|
||||||
|
/** Advance to next column */
|
||||||
|
void next_column();
|
||||||
|
|
||||||
|
/** Add padding to align with column width */
|
||||||
|
void align_to_column_width(size_t actual_width);
|
||||||
|
|
||||||
|
private:
|
||||||
|
fractured_json_options options_;
|
||||||
|
layout_mode current_layout_ = layout_mode::EXPANDED;
|
||||||
|
size_t current_depth_ = 0;
|
||||||
|
size_t current_line_length_ = 0;
|
||||||
|
|
||||||
|
// Table state
|
||||||
|
bool in_table_mode_ = false;
|
||||||
|
std::vector<size_t> column_widths_;
|
||||||
|
size_t current_column_ = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specialized string builder for fractured JSON formatting.
|
||||||
|
*
|
||||||
|
* This builder performs two passes:
|
||||||
|
* 1. Analyze the structure to compute metrics
|
||||||
|
* 2. Format using the metrics to make layout decisions
|
||||||
|
*/
|
||||||
|
class fractured_string_builder {
|
||||||
|
public:
|
||||||
|
fractured_string_builder(const fractured_json_options& opts = {});
|
||||||
|
|
||||||
|
/** Append a DOM element with fractured formatting */
|
||||||
|
void append(const dom::element& value);
|
||||||
|
|
||||||
|
/** Append a DOM array with fractured formatting */
|
||||||
|
void append(const dom::array& value);
|
||||||
|
|
||||||
|
/** Append a DOM object with fractured formatting */
|
||||||
|
void append(const dom::object& value);
|
||||||
|
|
||||||
|
/** Clear the builder */
|
||||||
|
simdjson_inline void clear();
|
||||||
|
|
||||||
|
/** Get the formatted string */
|
||||||
|
simdjson_inline std::string_view str() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
fractured_formatter format_;
|
||||||
|
structure_analyzer analyzer_;
|
||||||
|
fractured_json_options options_;
|
||||||
|
|
||||||
|
/** Format an element using pre-computed metrics */
|
||||||
|
void format_element(const dom::element& elem, const element_metrics& metrics, size_t depth);
|
||||||
|
|
||||||
|
/** Format an array with the appropriate layout */
|
||||||
|
void format_array(const dom::array& arr, const element_metrics& metrics, size_t depth);
|
||||||
|
|
||||||
|
/** Format an array inline: [1, 2, 3] */
|
||||||
|
void format_array_inline(const dom::array& arr, const element_metrics& metrics);
|
||||||
|
|
||||||
|
/** Format an array with compact multiline: multiple items per line */
|
||||||
|
void format_array_compact_multiline(const dom::array& arr, const element_metrics& metrics, size_t depth);
|
||||||
|
|
||||||
|
/** Format an array as a table */
|
||||||
|
void format_array_as_table(const dom::array& arr, const element_metrics& metrics, size_t depth);
|
||||||
|
|
||||||
|
/** Format an array expanded: one item per line */
|
||||||
|
void format_array_expanded(const dom::array& arr, const element_metrics& metrics, size_t depth);
|
||||||
|
|
||||||
|
/** Format an object with the appropriate layout */
|
||||||
|
void format_object(const dom::object& obj, const element_metrics& metrics, size_t depth);
|
||||||
|
|
||||||
|
/** Format an object inline: {"a": 1, "b": 2} */
|
||||||
|
void format_object_inline(const dom::object& obj, const element_metrics& metrics);
|
||||||
|
|
||||||
|
/** Format an object expanded: one key per line */
|
||||||
|
void format_object_expanded(const dom::object& obj, const element_metrics& metrics, size_t depth);
|
||||||
|
|
||||||
|
/** Format a scalar value */
|
||||||
|
void format_scalar(const dom::element& elem);
|
||||||
|
|
||||||
|
/** Calculate column widths for table formatting */
|
||||||
|
std::vector<size_t> calculate_column_widths(const dom::array& arr,
|
||||||
|
const std::vector<std::string>& columns) const;
|
||||||
|
|
||||||
|
/** Measure the actual formatted length of a value (for alignment) */
|
||||||
|
size_t measure_value_length(const dom::element& elem) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
} // namespace simdjson
|
||||||
|
|
||||||
|
#endif // SIMDJSON_INTERNAL_FRACTURED_FORMATTER_H
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
#ifndef SIMDJSON_INTERNAL_JSON_STRUCTURE_ANALYZER_H
|
||||||
|
#define SIMDJSON_INTERNAL_JSON_STRUCTURE_ANALYZER_H
|
||||||
|
|
||||||
|
#include "simdjson/dom/base.h"
|
||||||
|
#include "simdjson/dom/element.h"
|
||||||
|
#include "simdjson/dom/array.h"
|
||||||
|
#include "simdjson/dom/object.h"
|
||||||
|
#include "simdjson/dom/fractured_json.h"
|
||||||
|
#include "simdjson/internal/tape_type.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
namespace simdjson {
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Layout mode for fractured JSON formatting.
|
||||||
|
*/
|
||||||
|
enum class layout_mode {
|
||||||
|
INLINE, // Single line: [1, 2, 3] or {"a": 1}
|
||||||
|
COMPACT_MULTILINE, // Multiple items per line with breaks
|
||||||
|
TABLE, // Tabular format for arrays of similar objects
|
||||||
|
EXPANDED // Traditional multi-line with indentation
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metrics computed for a JSON element during structure analysis.
|
||||||
|
* These metrics drive layout decisions and contain child metrics for recursive formatting.
|
||||||
|
*/
|
||||||
|
struct element_metrics {
|
||||||
|
/** Nesting depth score (0 = scalar, 1 = flat container, etc.) */
|
||||||
|
size_t complexity = 0;
|
||||||
|
|
||||||
|
/** Estimated character length if rendered inline (minified + spaces) */
|
||||||
|
size_t estimated_inline_len = 0;
|
||||||
|
|
||||||
|
/** Number of direct children (0 for scalars) */
|
||||||
|
size_t child_count = 0;
|
||||||
|
|
||||||
|
/** Pre-computed: can this element be rendered inline? */
|
||||||
|
bool can_inline = false;
|
||||||
|
|
||||||
|
/** Is this an array where all elements have similar structure? */
|
||||||
|
bool is_uniform_array = false;
|
||||||
|
|
||||||
|
/** For uniform arrays of objects: the common keys */
|
||||||
|
std::vector<std::string> common_keys{};
|
||||||
|
|
||||||
|
/** Recommended layout mode based on analysis */
|
||||||
|
layout_mode recommended_layout = layout_mode::EXPANDED;
|
||||||
|
|
||||||
|
/** Child metrics for arrays and objects (in order of iteration) */
|
||||||
|
std::vector<element_metrics> children{};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyzes JSON structure to compute metrics for formatting decisions.
|
||||||
|
*
|
||||||
|
* The analyzer performs a single pass over the DOM to compute:
|
||||||
|
* - Complexity (nesting depth)
|
||||||
|
* - Estimated inline length
|
||||||
|
* - Array uniformity for table detection
|
||||||
|
*
|
||||||
|
* Metrics are stored hierarchically with child metrics embedded in parent metrics,
|
||||||
|
* enabling efficient lookup during formatting without address-based caching.
|
||||||
|
*/
|
||||||
|
class structure_analyzer {
|
||||||
|
public:
|
||||||
|
/** Default constructor */
|
||||||
|
structure_analyzer() : current_opts_(nullptr) {}
|
||||||
|
|
||||||
|
/** Copy constructor - deleted since class has pointer member */
|
||||||
|
structure_analyzer(const structure_analyzer&) = delete;
|
||||||
|
|
||||||
|
/** Copy assignment - deleted since class has pointer member */
|
||||||
|
structure_analyzer& operator=(const structure_analyzer&) = delete;
|
||||||
|
|
||||||
|
/** Move constructor */
|
||||||
|
structure_analyzer(structure_analyzer&&) = default;
|
||||||
|
|
||||||
|
/** Move assignment */
|
||||||
|
structure_analyzer& operator=(structure_analyzer&&) = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyze a DOM element and compute metrics.
|
||||||
|
* @param elem The element to analyze
|
||||||
|
* @param opts Formatting options that affect metric computation
|
||||||
|
* @return Metrics for the root element (with child metrics embedded)
|
||||||
|
*/
|
||||||
|
element_metrics analyze(const dom::element& elem,
|
||||||
|
const fractured_json_options& opts);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear state.
|
||||||
|
*/
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyze an array element directly (for standalone array formatting).
|
||||||
|
* @param arr The array to analyze
|
||||||
|
* @param opts Formatting options
|
||||||
|
* @return Metrics for the array
|
||||||
|
*/
|
||||||
|
element_metrics analyze_array(const dom::array& arr,
|
||||||
|
const fractured_json_options& opts);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyze an object element directly (for standalone object formatting).
|
||||||
|
* @param obj The object to analyze
|
||||||
|
* @param opts Formatting options
|
||||||
|
* @return Metrics for the object
|
||||||
|
*/
|
||||||
|
element_metrics analyze_object(const dom::object& obj,
|
||||||
|
const fractured_json_options& opts);
|
||||||
|
|
||||||
|
private:
|
||||||
|
const fractured_json_options* current_opts_ = nullptr;
|
||||||
|
|
||||||
|
/** Recursive analysis implementation */
|
||||||
|
element_metrics analyze_element(const dom::element& elem, size_t depth);
|
||||||
|
|
||||||
|
/** Analyze scalar values (strings, numbers, booleans, null) */
|
||||||
|
element_metrics analyze_scalar(const dom::element& elem);
|
||||||
|
|
||||||
|
/** Analyze an array element */
|
||||||
|
element_metrics analyze_array(const dom::array& arr, size_t depth);
|
||||||
|
|
||||||
|
/** Analyze an object element */
|
||||||
|
element_metrics analyze_object(const dom::object& obj, size_t depth);
|
||||||
|
|
||||||
|
/** Estimate inline length for a string (including quotes and escaping) */
|
||||||
|
size_t estimate_string_length(std::string_view s) const;
|
||||||
|
|
||||||
|
/** Estimate inline length for a number */
|
||||||
|
size_t estimate_number_length(double d) const;
|
||||||
|
size_t estimate_number_length(int64_t i) const;
|
||||||
|
size_t estimate_number_length(uint64_t u) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if an array contains uniform objects suitable for table formatting.
|
||||||
|
* @param arr The array to check
|
||||||
|
* @param common_keys Output: keys common to all objects
|
||||||
|
* @return true if the array is suitable for table formatting
|
||||||
|
*/
|
||||||
|
bool check_array_uniformity(const dom::array& arr,
|
||||||
|
std::vector<std::string>& common_keys) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute similarity between two objects.
|
||||||
|
* @return Fraction of keys that are common (0.0 to 1.0)
|
||||||
|
*/
|
||||||
|
double compute_object_similarity(const dom::object& a,
|
||||||
|
const dom::object& b) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decide the recommended layout mode based on metrics and options.
|
||||||
|
*/
|
||||||
|
layout_mode decide_layout(const element_metrics& metrics,
|
||||||
|
size_t depth,
|
||||||
|
size_t available_width) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
} // namespace simdjson
|
||||||
|
|
||||||
|
#endif // SIMDJSON_INTERNAL_JSON_STRUCTURE_ANALYZER_H
|
||||||
@@ -52,7 +52,665 @@ extern SIMDJSON_DLLIMPORTEXPORT const double power_of_ten[];
|
|||||||
// The truncated powers of five from 5^-342 all the way to 5^308
|
// The truncated powers of five from 5^-342 all the way to 5^308
|
||||||
// The mantissa is truncated to 128 bits, and
|
// The mantissa is truncated to 128 bits, and
|
||||||
// never rounded up. Uses about 10KB.
|
// never rounded up. Uses about 10KB.
|
||||||
extern SIMDJSON_DLLIMPORTEXPORT const uint64_t power_of_five_128[];
|
// We use the template trick to allow inclusion in multiple translation units.
|
||||||
|
#if SIMDJSON_STATIC_REFLECTION
|
||||||
|
template <typename unused = void> struct powers_template {
|
||||||
|
constexpr static uint64_t power_of_five_128[651*2]= {
|
||||||
|
0xeef453d6923bd65a,0x113faa2906a13b3f,
|
||||||
|
0x9558b4661b6565f8,0x4ac7ca59a424c507,
|
||||||
|
0xbaaee17fa23ebf76,0x5d79bcf00d2df649,
|
||||||
|
0xe95a99df8ace6f53,0xf4d82c2c107973dc,
|
||||||
|
0x91d8a02bb6c10594,0x79071b9b8a4be869,
|
||||||
|
0xb64ec836a47146f9,0x9748e2826cdee284,
|
||||||
|
0xe3e27a444d8d98b7,0xfd1b1b2308169b25,
|
||||||
|
0x8e6d8c6ab0787f72,0xfe30f0f5e50e20f7,
|
||||||
|
0xb208ef855c969f4f,0xbdbd2d335e51a935,
|
||||||
|
0xde8b2b66b3bc4723,0xad2c788035e61382,
|
||||||
|
0x8b16fb203055ac76,0x4c3bcb5021afcc31,
|
||||||
|
0xaddcb9e83c6b1793,0xdf4abe242a1bbf3d,
|
||||||
|
0xd953e8624b85dd78,0xd71d6dad34a2af0d,
|
||||||
|
0x87d4713d6f33aa6b,0x8672648c40e5ad68,
|
||||||
|
0xa9c98d8ccb009506,0x680efdaf511f18c2,
|
||||||
|
0xd43bf0effdc0ba48,0x212bd1b2566def2,
|
||||||
|
0x84a57695fe98746d,0x14bb630f7604b57,
|
||||||
|
0xa5ced43b7e3e9188,0x419ea3bd35385e2d,
|
||||||
|
0xcf42894a5dce35ea,0x52064cac828675b9,
|
||||||
|
0x818995ce7aa0e1b2,0x7343efebd1940993,
|
||||||
|
0xa1ebfb4219491a1f,0x1014ebe6c5f90bf8,
|
||||||
|
0xca66fa129f9b60a6,0xd41a26e077774ef6,
|
||||||
|
0xfd00b897478238d0,0x8920b098955522b4,
|
||||||
|
0x9e20735e8cb16382,0x55b46e5f5d5535b0,
|
||||||
|
0xc5a890362fddbc62,0xeb2189f734aa831d,
|
||||||
|
0xf712b443bbd52b7b,0xa5e9ec7501d523e4,
|
||||||
|
0x9a6bb0aa55653b2d,0x47b233c92125366e,
|
||||||
|
0xc1069cd4eabe89f8,0x999ec0bb696e840a,
|
||||||
|
0xf148440a256e2c76,0xc00670ea43ca250d,
|
||||||
|
0x96cd2a865764dbca,0x380406926a5e5728,
|
||||||
|
0xbc807527ed3e12bc,0xc605083704f5ecf2,
|
||||||
|
0xeba09271e88d976b,0xf7864a44c633682e,
|
||||||
|
0x93445b8731587ea3,0x7ab3ee6afbe0211d,
|
||||||
|
0xb8157268fdae9e4c,0x5960ea05bad82964,
|
||||||
|
0xe61acf033d1a45df,0x6fb92487298e33bd,
|
||||||
|
0x8fd0c16206306bab,0xa5d3b6d479f8e056,
|
||||||
|
0xb3c4f1ba87bc8696,0x8f48a4899877186c,
|
||||||
|
0xe0b62e2929aba83c,0x331acdabfe94de87,
|
||||||
|
0x8c71dcd9ba0b4925,0x9ff0c08b7f1d0b14,
|
||||||
|
0xaf8e5410288e1b6f,0x7ecf0ae5ee44dd9,
|
||||||
|
0xdb71e91432b1a24a,0xc9e82cd9f69d6150,
|
||||||
|
0x892731ac9faf056e,0xbe311c083a225cd2,
|
||||||
|
0xab70fe17c79ac6ca,0x6dbd630a48aaf406,
|
||||||
|
0xd64d3d9db981787d,0x92cbbccdad5b108,
|
||||||
|
0x85f0468293f0eb4e,0x25bbf56008c58ea5,
|
||||||
|
0xa76c582338ed2621,0xaf2af2b80af6f24e,
|
||||||
|
0xd1476e2c07286faa,0x1af5af660db4aee1,
|
||||||
|
0x82cca4db847945ca,0x50d98d9fc890ed4d,
|
||||||
|
0xa37fce126597973c,0xe50ff107bab528a0,
|
||||||
|
0xcc5fc196fefd7d0c,0x1e53ed49a96272c8,
|
||||||
|
0xff77b1fcbebcdc4f,0x25e8e89c13bb0f7a,
|
||||||
|
0x9faacf3df73609b1,0x77b191618c54e9ac,
|
||||||
|
0xc795830d75038c1d,0xd59df5b9ef6a2417,
|
||||||
|
0xf97ae3d0d2446f25,0x4b0573286b44ad1d,
|
||||||
|
0x9becce62836ac577,0x4ee367f9430aec32,
|
||||||
|
0xc2e801fb244576d5,0x229c41f793cda73f,
|
||||||
|
0xf3a20279ed56d48a,0x6b43527578c1110f,
|
||||||
|
0x9845418c345644d6,0x830a13896b78aaa9,
|
||||||
|
0xbe5691ef416bd60c,0x23cc986bc656d553,
|
||||||
|
0xedec366b11c6cb8f,0x2cbfbe86b7ec8aa8,
|
||||||
|
0x94b3a202eb1c3f39,0x7bf7d71432f3d6a9,
|
||||||
|
0xb9e08a83a5e34f07,0xdaf5ccd93fb0cc53,
|
||||||
|
0xe858ad248f5c22c9,0xd1b3400f8f9cff68,
|
||||||
|
0x91376c36d99995be,0x23100809b9c21fa1,
|
||||||
|
0xb58547448ffffb2d,0xabd40a0c2832a78a,
|
||||||
|
0xe2e69915b3fff9f9,0x16c90c8f323f516c,
|
||||||
|
0x8dd01fad907ffc3b,0xae3da7d97f6792e3,
|
||||||
|
0xb1442798f49ffb4a,0x99cd11cfdf41779c,
|
||||||
|
0xdd95317f31c7fa1d,0x40405643d711d583,
|
||||||
|
0x8a7d3eef7f1cfc52,0x482835ea666b2572,
|
||||||
|
0xad1c8eab5ee43b66,0xda3243650005eecf,
|
||||||
|
0xd863b256369d4a40,0x90bed43e40076a82,
|
||||||
|
0x873e4f75e2224e68,0x5a7744a6e804a291,
|
||||||
|
0xa90de3535aaae202,0x711515d0a205cb36,
|
||||||
|
0xd3515c2831559a83,0xd5a5b44ca873e03,
|
||||||
|
0x8412d9991ed58091,0xe858790afe9486c2,
|
||||||
|
0xa5178fff668ae0b6,0x626e974dbe39a872,
|
||||||
|
0xce5d73ff402d98e3,0xfb0a3d212dc8128f,
|
||||||
|
0x80fa687f881c7f8e,0x7ce66634bc9d0b99,
|
||||||
|
0xa139029f6a239f72,0x1c1fffc1ebc44e80,
|
||||||
|
0xc987434744ac874e,0xa327ffb266b56220,
|
||||||
|
0xfbe9141915d7a922,0x4bf1ff9f0062baa8,
|
||||||
|
0x9d71ac8fada6c9b5,0x6f773fc3603db4a9,
|
||||||
|
0xc4ce17b399107c22,0xcb550fb4384d21d3,
|
||||||
|
0xf6019da07f549b2b,0x7e2a53a146606a48,
|
||||||
|
0x99c102844f94e0fb,0x2eda7444cbfc426d,
|
||||||
|
0xc0314325637a1939,0xfa911155fefb5308,
|
||||||
|
0xf03d93eebc589f88,0x793555ab7eba27ca,
|
||||||
|
0x96267c7535b763b5,0x4bc1558b2f3458de,
|
||||||
|
0xbbb01b9283253ca2,0x9eb1aaedfb016f16,
|
||||||
|
0xea9c227723ee8bcb,0x465e15a979c1cadc,
|
||||||
|
0x92a1958a7675175f,0xbfacd89ec191ec9,
|
||||||
|
0xb749faed14125d36,0xcef980ec671f667b,
|
||||||
|
0xe51c79a85916f484,0x82b7e12780e7401a,
|
||||||
|
0x8f31cc0937ae58d2,0xd1b2ecb8b0908810,
|
||||||
|
0xb2fe3f0b8599ef07,0x861fa7e6dcb4aa15,
|
||||||
|
0xdfbdcece67006ac9,0x67a791e093e1d49a,
|
||||||
|
0x8bd6a141006042bd,0xe0c8bb2c5c6d24e0,
|
||||||
|
0xaecc49914078536d,0x58fae9f773886e18,
|
||||||
|
0xda7f5bf590966848,0xaf39a475506a899e,
|
||||||
|
0x888f99797a5e012d,0x6d8406c952429603,
|
||||||
|
0xaab37fd7d8f58178,0xc8e5087ba6d33b83,
|
||||||
|
0xd5605fcdcf32e1d6,0xfb1e4a9a90880a64,
|
||||||
|
0x855c3be0a17fcd26,0x5cf2eea09a55067f,
|
||||||
|
0xa6b34ad8c9dfc06f,0xf42faa48c0ea481e,
|
||||||
|
0xd0601d8efc57b08b,0xf13b94daf124da26,
|
||||||
|
0x823c12795db6ce57,0x76c53d08d6b70858,
|
||||||
|
0xa2cb1717b52481ed,0x54768c4b0c64ca6e,
|
||||||
|
0xcb7ddcdda26da268,0xa9942f5dcf7dfd09,
|
||||||
|
0xfe5d54150b090b02,0xd3f93b35435d7c4c,
|
||||||
|
0x9efa548d26e5a6e1,0xc47bc5014a1a6daf,
|
||||||
|
0xc6b8e9b0709f109a,0x359ab6419ca1091b,
|
||||||
|
0xf867241c8cc6d4c0,0xc30163d203c94b62,
|
||||||
|
0x9b407691d7fc44f8,0x79e0de63425dcf1d,
|
||||||
|
0xc21094364dfb5636,0x985915fc12f542e4,
|
||||||
|
0xf294b943e17a2bc4,0x3e6f5b7b17b2939d,
|
||||||
|
0x979cf3ca6cec5b5a,0xa705992ceecf9c42,
|
||||||
|
0xbd8430bd08277231,0x50c6ff782a838353,
|
||||||
|
0xece53cec4a314ebd,0xa4f8bf5635246428,
|
||||||
|
0x940f4613ae5ed136,0x871b7795e136be99,
|
||||||
|
0xb913179899f68584,0x28e2557b59846e3f,
|
||||||
|
0xe757dd7ec07426e5,0x331aeada2fe589cf,
|
||||||
|
0x9096ea6f3848984f,0x3ff0d2c85def7621,
|
||||||
|
0xb4bca50b065abe63,0xfed077a756b53a9,
|
||||||
|
0xe1ebce4dc7f16dfb,0xd3e8495912c62894,
|
||||||
|
0x8d3360f09cf6e4bd,0x64712dd7abbbd95c,
|
||||||
|
0xb080392cc4349dec,0xbd8d794d96aacfb3,
|
||||||
|
0xdca04777f541c567,0xecf0d7a0fc5583a0,
|
||||||
|
0x89e42caaf9491b60,0xf41686c49db57244,
|
||||||
|
0xac5d37d5b79b6239,0x311c2875c522ced5,
|
||||||
|
0xd77485cb25823ac7,0x7d633293366b828b,
|
||||||
|
0x86a8d39ef77164bc,0xae5dff9c02033197,
|
||||||
|
0xa8530886b54dbdeb,0xd9f57f830283fdfc,
|
||||||
|
0xd267caa862a12d66,0xd072df63c324fd7b,
|
||||||
|
0x8380dea93da4bc60,0x4247cb9e59f71e6d,
|
||||||
|
0xa46116538d0deb78,0x52d9be85f074e608,
|
||||||
|
0xcd795be870516656,0x67902e276c921f8b,
|
||||||
|
0x806bd9714632dff6,0xba1cd8a3db53b6,
|
||||||
|
0xa086cfcd97bf97f3,0x80e8a40eccd228a4,
|
||||||
|
0xc8a883c0fdaf7df0,0x6122cd128006b2cd,
|
||||||
|
0xfad2a4b13d1b5d6c,0x796b805720085f81,
|
||||||
|
0x9cc3a6eec6311a63,0xcbe3303674053bb0,
|
||||||
|
0xc3f490aa77bd60fc,0xbedbfc4411068a9c,
|
||||||
|
0xf4f1b4d515acb93b,0xee92fb5515482d44,
|
||||||
|
0x991711052d8bf3c5,0x751bdd152d4d1c4a,
|
||||||
|
0xbf5cd54678eef0b6,0xd262d45a78a0635d,
|
||||||
|
0xef340a98172aace4,0x86fb897116c87c34,
|
||||||
|
0x9580869f0e7aac0e,0xd45d35e6ae3d4da0,
|
||||||
|
0xbae0a846d2195712,0x8974836059cca109,
|
||||||
|
0xe998d258869facd7,0x2bd1a438703fc94b,
|
||||||
|
0x91ff83775423cc06,0x7b6306a34627ddcf,
|
||||||
|
0xb67f6455292cbf08,0x1a3bc84c17b1d542,
|
||||||
|
0xe41f3d6a7377eeca,0x20caba5f1d9e4a93,
|
||||||
|
0x8e938662882af53e,0x547eb47b7282ee9c,
|
||||||
|
0xb23867fb2a35b28d,0xe99e619a4f23aa43,
|
||||||
|
0xdec681f9f4c31f31,0x6405fa00e2ec94d4,
|
||||||
|
0x8b3c113c38f9f37e,0xde83bc408dd3dd04,
|
||||||
|
0xae0b158b4738705e,0x9624ab50b148d445,
|
||||||
|
0xd98ddaee19068c76,0x3badd624dd9b0957,
|
||||||
|
0x87f8a8d4cfa417c9,0xe54ca5d70a80e5d6,
|
||||||
|
0xa9f6d30a038d1dbc,0x5e9fcf4ccd211f4c,
|
||||||
|
0xd47487cc8470652b,0x7647c3200069671f,
|
||||||
|
0x84c8d4dfd2c63f3b,0x29ecd9f40041e073,
|
||||||
|
0xa5fb0a17c777cf09,0xf468107100525890,
|
||||||
|
0xcf79cc9db955c2cc,0x7182148d4066eeb4,
|
||||||
|
0x81ac1fe293d599bf,0xc6f14cd848405530,
|
||||||
|
0xa21727db38cb002f,0xb8ada00e5a506a7c,
|
||||||
|
0xca9cf1d206fdc03b,0xa6d90811f0e4851c,
|
||||||
|
0xfd442e4688bd304a,0x908f4a166d1da663,
|
||||||
|
0x9e4a9cec15763e2e,0x9a598e4e043287fe,
|
||||||
|
0xc5dd44271ad3cdba,0x40eff1e1853f29fd,
|
||||||
|
0xf7549530e188c128,0xd12bee59e68ef47c,
|
||||||
|
0x9a94dd3e8cf578b9,0x82bb74f8301958ce,
|
||||||
|
0xc13a148e3032d6e7,0xe36a52363c1faf01,
|
||||||
|
0xf18899b1bc3f8ca1,0xdc44e6c3cb279ac1,
|
||||||
|
0x96f5600f15a7b7e5,0x29ab103a5ef8c0b9,
|
||||||
|
0xbcb2b812db11a5de,0x7415d448f6b6f0e7,
|
||||||
|
0xebdf661791d60f56,0x111b495b3464ad21,
|
||||||
|
0x936b9fcebb25c995,0xcab10dd900beec34,
|
||||||
|
0xb84687c269ef3bfb,0x3d5d514f40eea742,
|
||||||
|
0xe65829b3046b0afa,0xcb4a5a3112a5112,
|
||||||
|
0x8ff71a0fe2c2e6dc,0x47f0e785eaba72ab,
|
||||||
|
0xb3f4e093db73a093,0x59ed216765690f56,
|
||||||
|
0xe0f218b8d25088b8,0x306869c13ec3532c,
|
||||||
|
0x8c974f7383725573,0x1e414218c73a13fb,
|
||||||
|
0xafbd2350644eeacf,0xe5d1929ef90898fa,
|
||||||
|
0xdbac6c247d62a583,0xdf45f746b74abf39,
|
||||||
|
0x894bc396ce5da772,0x6b8bba8c328eb783,
|
||||||
|
0xab9eb47c81f5114f,0x66ea92f3f326564,
|
||||||
|
0xd686619ba27255a2,0xc80a537b0efefebd,
|
||||||
|
0x8613fd0145877585,0xbd06742ce95f5f36,
|
||||||
|
0xa798fc4196e952e7,0x2c48113823b73704,
|
||||||
|
0xd17f3b51fca3a7a0,0xf75a15862ca504c5,
|
||||||
|
0x82ef85133de648c4,0x9a984d73dbe722fb,
|
||||||
|
0xa3ab66580d5fdaf5,0xc13e60d0d2e0ebba,
|
||||||
|
0xcc963fee10b7d1b3,0x318df905079926a8,
|
||||||
|
0xffbbcfe994e5c61f,0xfdf17746497f7052,
|
||||||
|
0x9fd561f1fd0f9bd3,0xfeb6ea8bedefa633,
|
||||||
|
0xc7caba6e7c5382c8,0xfe64a52ee96b8fc0,
|
||||||
|
0xf9bd690a1b68637b,0x3dfdce7aa3c673b0,
|
||||||
|
0x9c1661a651213e2d,0x6bea10ca65c084e,
|
||||||
|
0xc31bfa0fe5698db8,0x486e494fcff30a62,
|
||||||
|
0xf3e2f893dec3f126,0x5a89dba3c3efccfa,
|
||||||
|
0x986ddb5c6b3a76b7,0xf89629465a75e01c,
|
||||||
|
0xbe89523386091465,0xf6bbb397f1135823,
|
||||||
|
0xee2ba6c0678b597f,0x746aa07ded582e2c,
|
||||||
|
0x94db483840b717ef,0xa8c2a44eb4571cdc,
|
||||||
|
0xba121a4650e4ddeb,0x92f34d62616ce413,
|
||||||
|
0xe896a0d7e51e1566,0x77b020baf9c81d17,
|
||||||
|
0x915e2486ef32cd60,0xace1474dc1d122e,
|
||||||
|
0xb5b5ada8aaff80b8,0xd819992132456ba,
|
||||||
|
0xe3231912d5bf60e6,0x10e1fff697ed6c69,
|
||||||
|
0x8df5efabc5979c8f,0xca8d3ffa1ef463c1,
|
||||||
|
0xb1736b96b6fd83b3,0xbd308ff8a6b17cb2,
|
||||||
|
0xddd0467c64bce4a0,0xac7cb3f6d05ddbde,
|
||||||
|
0x8aa22c0dbef60ee4,0x6bcdf07a423aa96b,
|
||||||
|
0xad4ab7112eb3929d,0x86c16c98d2c953c6,
|
||||||
|
0xd89d64d57a607744,0xe871c7bf077ba8b7,
|
||||||
|
0x87625f056c7c4a8b,0x11471cd764ad4972,
|
||||||
|
0xa93af6c6c79b5d2d,0xd598e40d3dd89bcf,
|
||||||
|
0xd389b47879823479,0x4aff1d108d4ec2c3,
|
||||||
|
0x843610cb4bf160cb,0xcedf722a585139ba,
|
||||||
|
0xa54394fe1eedb8fe,0xc2974eb4ee658828,
|
||||||
|
0xce947a3da6a9273e,0x733d226229feea32,
|
||||||
|
0x811ccc668829b887,0x806357d5a3f525f,
|
||||||
|
0xa163ff802a3426a8,0xca07c2dcb0cf26f7,
|
||||||
|
0xc9bcff6034c13052,0xfc89b393dd02f0b5,
|
||||||
|
0xfc2c3f3841f17c67,0xbbac2078d443ace2,
|
||||||
|
0x9d9ba7832936edc0,0xd54b944b84aa4c0d,
|
||||||
|
0xc5029163f384a931,0xa9e795e65d4df11,
|
||||||
|
0xf64335bcf065d37d,0x4d4617b5ff4a16d5,
|
||||||
|
0x99ea0196163fa42e,0x504bced1bf8e4e45,
|
||||||
|
0xc06481fb9bcf8d39,0xe45ec2862f71e1d6,
|
||||||
|
0xf07da27a82c37088,0x5d767327bb4e5a4c,
|
||||||
|
0x964e858c91ba2655,0x3a6a07f8d510f86f,
|
||||||
|
0xbbe226efb628afea,0x890489f70a55368b,
|
||||||
|
0xeadab0aba3b2dbe5,0x2b45ac74ccea842e,
|
||||||
|
0x92c8ae6b464fc96f,0x3b0b8bc90012929d,
|
||||||
|
0xb77ada0617e3bbcb,0x9ce6ebb40173744,
|
||||||
|
0xe55990879ddcaabd,0xcc420a6a101d0515,
|
||||||
|
0x8f57fa54c2a9eab6,0x9fa946824a12232d,
|
||||||
|
0xb32df8e9f3546564,0x47939822dc96abf9,
|
||||||
|
0xdff9772470297ebd,0x59787e2b93bc56f7,
|
||||||
|
0x8bfbea76c619ef36,0x57eb4edb3c55b65a,
|
||||||
|
0xaefae51477a06b03,0xede622920b6b23f1,
|
||||||
|
0xdab99e59958885c4,0xe95fab368e45eced,
|
||||||
|
0x88b402f7fd75539b,0x11dbcb0218ebb414,
|
||||||
|
0xaae103b5fcd2a881,0xd652bdc29f26a119,
|
||||||
|
0xd59944a37c0752a2,0x4be76d3346f0495f,
|
||||||
|
0x857fcae62d8493a5,0x6f70a4400c562ddb,
|
||||||
|
0xa6dfbd9fb8e5b88e,0xcb4ccd500f6bb952,
|
||||||
|
0xd097ad07a71f26b2,0x7e2000a41346a7a7,
|
||||||
|
0x825ecc24c873782f,0x8ed400668c0c28c8,
|
||||||
|
0xa2f67f2dfa90563b,0x728900802f0f32fa,
|
||||||
|
0xcbb41ef979346bca,0x4f2b40a03ad2ffb9,
|
||||||
|
0xfea126b7d78186bc,0xe2f610c84987bfa8,
|
||||||
|
0x9f24b832e6b0f436,0xdd9ca7d2df4d7c9,
|
||||||
|
0xc6ede63fa05d3143,0x91503d1c79720dbb,
|
||||||
|
0xf8a95fcf88747d94,0x75a44c6397ce912a,
|
||||||
|
0x9b69dbe1b548ce7c,0xc986afbe3ee11aba,
|
||||||
|
0xc24452da229b021b,0xfbe85badce996168,
|
||||||
|
0xf2d56790ab41c2a2,0xfae27299423fb9c3,
|
||||||
|
0x97c560ba6b0919a5,0xdccd879fc967d41a,
|
||||||
|
0xbdb6b8e905cb600f,0x5400e987bbc1c920,
|
||||||
|
0xed246723473e3813,0x290123e9aab23b68,
|
||||||
|
0x9436c0760c86e30b,0xf9a0b6720aaf6521,
|
||||||
|
0xb94470938fa89bce,0xf808e40e8d5b3e69,
|
||||||
|
0xe7958cb87392c2c2,0xb60b1d1230b20e04,
|
||||||
|
0x90bd77f3483bb9b9,0xb1c6f22b5e6f48c2,
|
||||||
|
0xb4ecd5f01a4aa828,0x1e38aeb6360b1af3,
|
||||||
|
0xe2280b6c20dd5232,0x25c6da63c38de1b0,
|
||||||
|
0x8d590723948a535f,0x579c487e5a38ad0e,
|
||||||
|
0xb0af48ec79ace837,0x2d835a9df0c6d851,
|
||||||
|
0xdcdb1b2798182244,0xf8e431456cf88e65,
|
||||||
|
0x8a08f0f8bf0f156b,0x1b8e9ecb641b58ff,
|
||||||
|
0xac8b2d36eed2dac5,0xe272467e3d222f3f,
|
||||||
|
0xd7adf884aa879177,0x5b0ed81dcc6abb0f,
|
||||||
|
0x86ccbb52ea94baea,0x98e947129fc2b4e9,
|
||||||
|
0xa87fea27a539e9a5,0x3f2398d747b36224,
|
||||||
|
0xd29fe4b18e88640e,0x8eec7f0d19a03aad,
|
||||||
|
0x83a3eeeef9153e89,0x1953cf68300424ac,
|
||||||
|
0xa48ceaaab75a8e2b,0x5fa8c3423c052dd7,
|
||||||
|
0xcdb02555653131b6,0x3792f412cb06794d,
|
||||||
|
0x808e17555f3ebf11,0xe2bbd88bbee40bd0,
|
||||||
|
0xa0b19d2ab70e6ed6,0x5b6aceaeae9d0ec4,
|
||||||
|
0xc8de047564d20a8b,0xf245825a5a445275,
|
||||||
|
0xfb158592be068d2e,0xeed6e2f0f0d56712,
|
||||||
|
0x9ced737bb6c4183d,0x55464dd69685606b,
|
||||||
|
0xc428d05aa4751e4c,0xaa97e14c3c26b886,
|
||||||
|
0xf53304714d9265df,0xd53dd99f4b3066a8,
|
||||||
|
0x993fe2c6d07b7fab,0xe546a8038efe4029,
|
||||||
|
0xbf8fdb78849a5f96,0xde98520472bdd033,
|
||||||
|
0xef73d256a5c0f77c,0x963e66858f6d4440,
|
||||||
|
0x95a8637627989aad,0xdde7001379a44aa8,
|
||||||
|
0xbb127c53b17ec159,0x5560c018580d5d52,
|
||||||
|
0xe9d71b689dde71af,0xaab8f01e6e10b4a6,
|
||||||
|
0x9226712162ab070d,0xcab3961304ca70e8,
|
||||||
|
0xb6b00d69bb55c8d1,0x3d607b97c5fd0d22,
|
||||||
|
0xe45c10c42a2b3b05,0x8cb89a7db77c506a,
|
||||||
|
0x8eb98a7a9a5b04e3,0x77f3608e92adb242,
|
||||||
|
0xb267ed1940f1c61c,0x55f038b237591ed3,
|
||||||
|
0xdf01e85f912e37a3,0x6b6c46dec52f6688,
|
||||||
|
0x8b61313bbabce2c6,0x2323ac4b3b3da015,
|
||||||
|
0xae397d8aa96c1b77,0xabec975e0a0d081a,
|
||||||
|
0xd9c7dced53c72255,0x96e7bd358c904a21,
|
||||||
|
0x881cea14545c7575,0x7e50d64177da2e54,
|
||||||
|
0xaa242499697392d2,0xdde50bd1d5d0b9e9,
|
||||||
|
0xd4ad2dbfc3d07787,0x955e4ec64b44e864,
|
||||||
|
0x84ec3c97da624ab4,0xbd5af13bef0b113e,
|
||||||
|
0xa6274bbdd0fadd61,0xecb1ad8aeacdd58e,
|
||||||
|
0xcfb11ead453994ba,0x67de18eda5814af2,
|
||||||
|
0x81ceb32c4b43fcf4,0x80eacf948770ced7,
|
||||||
|
0xa2425ff75e14fc31,0xa1258379a94d028d,
|
||||||
|
0xcad2f7f5359a3b3e,0x96ee45813a04330,
|
||||||
|
0xfd87b5f28300ca0d,0x8bca9d6e188853fc,
|
||||||
|
0x9e74d1b791e07e48,0x775ea264cf55347e,
|
||||||
|
0xc612062576589dda,0x95364afe032a81a0,
|
||||||
|
0xf79687aed3eec551,0x3a83ddbd83f52210,
|
||||||
|
0x9abe14cd44753b52,0xc4926a9672793580,
|
||||||
|
0xc16d9a0095928a27,0x75b7053c0f178400,
|
||||||
|
0xf1c90080baf72cb1,0x5324c68b12dd6800,
|
||||||
|
0x971da05074da7bee,0xd3f6fc16ebca8000,
|
||||||
|
0xbce5086492111aea,0x88f4bb1ca6bd0000,
|
||||||
|
0xec1e4a7db69561a5,0x2b31e9e3d0700000,
|
||||||
|
0x9392ee8e921d5d07,0x3aff322e62600000,
|
||||||
|
0xb877aa3236a4b449,0x9befeb9fad487c3,
|
||||||
|
0xe69594bec44de15b,0x4c2ebe687989a9b4,
|
||||||
|
0x901d7cf73ab0acd9,0xf9d37014bf60a11,
|
||||||
|
0xb424dc35095cd80f,0x538484c19ef38c95,
|
||||||
|
0xe12e13424bb40e13,0x2865a5f206b06fba,
|
||||||
|
0x8cbccc096f5088cb,0xf93f87b7442e45d4,
|
||||||
|
0xafebff0bcb24aafe,0xf78f69a51539d749,
|
||||||
|
0xdbe6fecebdedd5be,0xb573440e5a884d1c,
|
||||||
|
0x89705f4136b4a597,0x31680a88f8953031,
|
||||||
|
0xabcc77118461cefc,0xfdc20d2b36ba7c3e,
|
||||||
|
0xd6bf94d5e57a42bc,0x3d32907604691b4d,
|
||||||
|
0x8637bd05af6c69b5,0xa63f9a49c2c1b110,
|
||||||
|
0xa7c5ac471b478423,0xfcf80dc33721d54,
|
||||||
|
0xd1b71758e219652b,0xd3c36113404ea4a9,
|
||||||
|
0x83126e978d4fdf3b,0x645a1cac083126ea,
|
||||||
|
0xa3d70a3d70a3d70a,0x3d70a3d70a3d70a4,
|
||||||
|
0xcccccccccccccccc,0xcccccccccccccccd,
|
||||||
|
0x8000000000000000,0x0,
|
||||||
|
0xa000000000000000,0x0,
|
||||||
|
0xc800000000000000,0x0,
|
||||||
|
0xfa00000000000000,0x0,
|
||||||
|
0x9c40000000000000,0x0,
|
||||||
|
0xc350000000000000,0x0,
|
||||||
|
0xf424000000000000,0x0,
|
||||||
|
0x9896800000000000,0x0,
|
||||||
|
0xbebc200000000000,0x0,
|
||||||
|
0xee6b280000000000,0x0,
|
||||||
|
0x9502f90000000000,0x0,
|
||||||
|
0xba43b74000000000,0x0,
|
||||||
|
0xe8d4a51000000000,0x0,
|
||||||
|
0x9184e72a00000000,0x0,
|
||||||
|
0xb5e620f480000000,0x0,
|
||||||
|
0xe35fa931a0000000,0x0,
|
||||||
|
0x8e1bc9bf04000000,0x0,
|
||||||
|
0xb1a2bc2ec5000000,0x0,
|
||||||
|
0xde0b6b3a76400000,0x0,
|
||||||
|
0x8ac7230489e80000,0x0,
|
||||||
|
0xad78ebc5ac620000,0x0,
|
||||||
|
0xd8d726b7177a8000,0x0,
|
||||||
|
0x878678326eac9000,0x0,
|
||||||
|
0xa968163f0a57b400,0x0,
|
||||||
|
0xd3c21bcecceda100,0x0,
|
||||||
|
0x84595161401484a0,0x0,
|
||||||
|
0xa56fa5b99019a5c8,0x0,
|
||||||
|
0xcecb8f27f4200f3a,0x0,
|
||||||
|
0x813f3978f8940984,0x4000000000000000,
|
||||||
|
0xa18f07d736b90be5,0x5000000000000000,
|
||||||
|
0xc9f2c9cd04674ede,0xa400000000000000,
|
||||||
|
0xfc6f7c4045812296,0x4d00000000000000,
|
||||||
|
0x9dc5ada82b70b59d,0xf020000000000000,
|
||||||
|
0xc5371912364ce305,0x6c28000000000000,
|
||||||
|
0xf684df56c3e01bc6,0xc732000000000000,
|
||||||
|
0x9a130b963a6c115c,0x3c7f400000000000,
|
||||||
|
0xc097ce7bc90715b3,0x4b9f100000000000,
|
||||||
|
0xf0bdc21abb48db20,0x1e86d40000000000,
|
||||||
|
0x96769950b50d88f4,0x1314448000000000,
|
||||||
|
0xbc143fa4e250eb31,0x17d955a000000000,
|
||||||
|
0xeb194f8e1ae525fd,0x5dcfab0800000000,
|
||||||
|
0x92efd1b8d0cf37be,0x5aa1cae500000000,
|
||||||
|
0xb7abc627050305ad,0xf14a3d9e40000000,
|
||||||
|
0xe596b7b0c643c719,0x6d9ccd05d0000000,
|
||||||
|
0x8f7e32ce7bea5c6f,0xe4820023a2000000,
|
||||||
|
0xb35dbf821ae4f38b,0xdda2802c8a800000,
|
||||||
|
0xe0352f62a19e306e,0xd50b2037ad200000,
|
||||||
|
0x8c213d9da502de45,0x4526f422cc340000,
|
||||||
|
0xaf298d050e4395d6,0x9670b12b7f410000,
|
||||||
|
0xdaf3f04651d47b4c,0x3c0cdd765f114000,
|
||||||
|
0x88d8762bf324cd0f,0xa5880a69fb6ac800,
|
||||||
|
0xab0e93b6efee0053,0x8eea0d047a457a00,
|
||||||
|
0xd5d238a4abe98068,0x72a4904598d6d880,
|
||||||
|
0x85a36366eb71f041,0x47a6da2b7f864750,
|
||||||
|
0xa70c3c40a64e6c51,0x999090b65f67d924,
|
||||||
|
0xd0cf4b50cfe20765,0xfff4b4e3f741cf6d,
|
||||||
|
0x82818f1281ed449f,0xbff8f10e7a8921a4,
|
||||||
|
0xa321f2d7226895c7,0xaff72d52192b6a0d,
|
||||||
|
0xcbea6f8ceb02bb39,0x9bf4f8a69f764490,
|
||||||
|
0xfee50b7025c36a08,0x2f236d04753d5b4,
|
||||||
|
0x9f4f2726179a2245,0x1d762422c946590,
|
||||||
|
0xc722f0ef9d80aad6,0x424d3ad2b7b97ef5,
|
||||||
|
0xf8ebad2b84e0d58b,0xd2e0898765a7deb2,
|
||||||
|
0x9b934c3b330c8577,0x63cc55f49f88eb2f,
|
||||||
|
0xc2781f49ffcfa6d5,0x3cbf6b71c76b25fb,
|
||||||
|
0xf316271c7fc3908a,0x8bef464e3945ef7a,
|
||||||
|
0x97edd871cfda3a56,0x97758bf0e3cbb5ac,
|
||||||
|
0xbde94e8e43d0c8ec,0x3d52eeed1cbea317,
|
||||||
|
0xed63a231d4c4fb27,0x4ca7aaa863ee4bdd,
|
||||||
|
0x945e455f24fb1cf8,0x8fe8caa93e74ef6a,
|
||||||
|
0xb975d6b6ee39e436,0xb3e2fd538e122b44,
|
||||||
|
0xe7d34c64a9c85d44,0x60dbbca87196b616,
|
||||||
|
0x90e40fbeea1d3a4a,0xbc8955e946fe31cd,
|
||||||
|
0xb51d13aea4a488dd,0x6babab6398bdbe41,
|
||||||
|
0xe264589a4dcdab14,0xc696963c7eed2dd1,
|
||||||
|
0x8d7eb76070a08aec,0xfc1e1de5cf543ca2,
|
||||||
|
0xb0de65388cc8ada8,0x3b25a55f43294bcb,
|
||||||
|
0xdd15fe86affad912,0x49ef0eb713f39ebe,
|
||||||
|
0x8a2dbf142dfcc7ab,0x6e3569326c784337,
|
||||||
|
0xacb92ed9397bf996,0x49c2c37f07965404,
|
||||||
|
0xd7e77a8f87daf7fb,0xdc33745ec97be906,
|
||||||
|
0x86f0ac99b4e8dafd,0x69a028bb3ded71a3,
|
||||||
|
0xa8acd7c0222311bc,0xc40832ea0d68ce0c,
|
||||||
|
0xd2d80db02aabd62b,0xf50a3fa490c30190,
|
||||||
|
0x83c7088e1aab65db,0x792667c6da79e0fa,
|
||||||
|
0xa4b8cab1a1563f52,0x577001b891185938,
|
||||||
|
0xcde6fd5e09abcf26,0xed4c0226b55e6f86,
|
||||||
|
0x80b05e5ac60b6178,0x544f8158315b05b4,
|
||||||
|
0xa0dc75f1778e39d6,0x696361ae3db1c721,
|
||||||
|
0xc913936dd571c84c,0x3bc3a19cd1e38e9,
|
||||||
|
0xfb5878494ace3a5f,0x4ab48a04065c723,
|
||||||
|
0x9d174b2dcec0e47b,0x62eb0d64283f9c76,
|
||||||
|
0xc45d1df942711d9a,0x3ba5d0bd324f8394,
|
||||||
|
0xf5746577930d6500,0xca8f44ec7ee36479,
|
||||||
|
0x9968bf6abbe85f20,0x7e998b13cf4e1ecb,
|
||||||
|
0xbfc2ef456ae276e8,0x9e3fedd8c321a67e,
|
||||||
|
0xefb3ab16c59b14a2,0xc5cfe94ef3ea101e,
|
||||||
|
0x95d04aee3b80ece5,0xbba1f1d158724a12,
|
||||||
|
0xbb445da9ca61281f,0x2a8a6e45ae8edc97,
|
||||||
|
0xea1575143cf97226,0xf52d09d71a3293bd,
|
||||||
|
0x924d692ca61be758,0x593c2626705f9c56,
|
||||||
|
0xb6e0c377cfa2e12e,0x6f8b2fb00c77836c,
|
||||||
|
0xe498f455c38b997a,0xb6dfb9c0f956447,
|
||||||
|
0x8edf98b59a373fec,0x4724bd4189bd5eac,
|
||||||
|
0xb2977ee300c50fe7,0x58edec91ec2cb657,
|
||||||
|
0xdf3d5e9bc0f653e1,0x2f2967b66737e3ed,
|
||||||
|
0x8b865b215899f46c,0xbd79e0d20082ee74,
|
||||||
|
0xae67f1e9aec07187,0xecd8590680a3aa11,
|
||||||
|
0xda01ee641a708de9,0xe80e6f4820cc9495,
|
||||||
|
0x884134fe908658b2,0x3109058d147fdcdd,
|
||||||
|
0xaa51823e34a7eede,0xbd4b46f0599fd415,
|
||||||
|
0xd4e5e2cdc1d1ea96,0x6c9e18ac7007c91a,
|
||||||
|
0x850fadc09923329e,0x3e2cf6bc604ddb0,
|
||||||
|
0xa6539930bf6bff45,0x84db8346b786151c,
|
||||||
|
0xcfe87f7cef46ff16,0xe612641865679a63,
|
||||||
|
0x81f14fae158c5f6e,0x4fcb7e8f3f60c07e,
|
||||||
|
0xa26da3999aef7749,0xe3be5e330f38f09d,
|
||||||
|
0xcb090c8001ab551c,0x5cadf5bfd3072cc5,
|
||||||
|
0xfdcb4fa002162a63,0x73d9732fc7c8f7f6,
|
||||||
|
0x9e9f11c4014dda7e,0x2867e7fddcdd9afa,
|
||||||
|
0xc646d63501a1511d,0xb281e1fd541501b8,
|
||||||
|
0xf7d88bc24209a565,0x1f225a7ca91a4226,
|
||||||
|
0x9ae757596946075f,0x3375788de9b06958,
|
||||||
|
0xc1a12d2fc3978937,0x52d6b1641c83ae,
|
||||||
|
0xf209787bb47d6b84,0xc0678c5dbd23a49a,
|
||||||
|
0x9745eb4d50ce6332,0xf840b7ba963646e0,
|
||||||
|
0xbd176620a501fbff,0xb650e5a93bc3d898,
|
||||||
|
0xec5d3fa8ce427aff,0xa3e51f138ab4cebe,
|
||||||
|
0x93ba47c980e98cdf,0xc66f336c36b10137,
|
||||||
|
0xb8a8d9bbe123f017,0xb80b0047445d4184,
|
||||||
|
0xe6d3102ad96cec1d,0xa60dc059157491e5,
|
||||||
|
0x9043ea1ac7e41392,0x87c89837ad68db2f,
|
||||||
|
0xb454e4a179dd1877,0x29babe4598c311fb,
|
||||||
|
0xe16a1dc9d8545e94,0xf4296dd6fef3d67a,
|
||||||
|
0x8ce2529e2734bb1d,0x1899e4a65f58660c,
|
||||||
|
0xb01ae745b101e9e4,0x5ec05dcff72e7f8f,
|
||||||
|
0xdc21a1171d42645d,0x76707543f4fa1f73,
|
||||||
|
0x899504ae72497eba,0x6a06494a791c53a8,
|
||||||
|
0xabfa45da0edbde69,0x487db9d17636892,
|
||||||
|
0xd6f8d7509292d603,0x45a9d2845d3c42b6,
|
||||||
|
0x865b86925b9bc5c2,0xb8a2392ba45a9b2,
|
||||||
|
0xa7f26836f282b732,0x8e6cac7768d7141e,
|
||||||
|
0xd1ef0244af2364ff,0x3207d795430cd926,
|
||||||
|
0x8335616aed761f1f,0x7f44e6bd49e807b8,
|
||||||
|
0xa402b9c5a8d3a6e7,0x5f16206c9c6209a6,
|
||||||
|
0xcd036837130890a1,0x36dba887c37a8c0f,
|
||||||
|
0x802221226be55a64,0xc2494954da2c9789,
|
||||||
|
0xa02aa96b06deb0fd,0xf2db9baa10b7bd6c,
|
||||||
|
0xc83553c5c8965d3d,0x6f92829494e5acc7,
|
||||||
|
0xfa42a8b73abbf48c,0xcb772339ba1f17f9,
|
||||||
|
0x9c69a97284b578d7,0xff2a760414536efb,
|
||||||
|
0xc38413cf25e2d70d,0xfef5138519684aba,
|
||||||
|
0xf46518c2ef5b8cd1,0x7eb258665fc25d69,
|
||||||
|
0x98bf2f79d5993802,0xef2f773ffbd97a61,
|
||||||
|
0xbeeefb584aff8603,0xaafb550ffacfd8fa,
|
||||||
|
0xeeaaba2e5dbf6784,0x95ba2a53f983cf38,
|
||||||
|
0x952ab45cfa97a0b2,0xdd945a747bf26183,
|
||||||
|
0xba756174393d88df,0x94f971119aeef9e4,
|
||||||
|
0xe912b9d1478ceb17,0x7a37cd5601aab85d,
|
||||||
|
0x91abb422ccb812ee,0xac62e055c10ab33a,
|
||||||
|
0xb616a12b7fe617aa,0x577b986b314d6009,
|
||||||
|
0xe39c49765fdf9d94,0xed5a7e85fda0b80b,
|
||||||
|
0x8e41ade9fbebc27d,0x14588f13be847307,
|
||||||
|
0xb1d219647ae6b31c,0x596eb2d8ae258fc8,
|
||||||
|
0xde469fbd99a05fe3,0x6fca5f8ed9aef3bb,
|
||||||
|
0x8aec23d680043bee,0x25de7bb9480d5854,
|
||||||
|
0xada72ccc20054ae9,0xaf561aa79a10ae6a,
|
||||||
|
0xd910f7ff28069da4,0x1b2ba1518094da04,
|
||||||
|
0x87aa9aff79042286,0x90fb44d2f05d0842,
|
||||||
|
0xa99541bf57452b28,0x353a1607ac744a53,
|
||||||
|
0xd3fa922f2d1675f2,0x42889b8997915ce8,
|
||||||
|
0x847c9b5d7c2e09b7,0x69956135febada11,
|
||||||
|
0xa59bc234db398c25,0x43fab9837e699095,
|
||||||
|
0xcf02b2c21207ef2e,0x94f967e45e03f4bb,
|
||||||
|
0x8161afb94b44f57d,0x1d1be0eebac278f5,
|
||||||
|
0xa1ba1ba79e1632dc,0x6462d92a69731732,
|
||||||
|
0xca28a291859bbf93,0x7d7b8f7503cfdcfe,
|
||||||
|
0xfcb2cb35e702af78,0x5cda735244c3d43e,
|
||||||
|
0x9defbf01b061adab,0x3a0888136afa64a7,
|
||||||
|
0xc56baec21c7a1916,0x88aaa1845b8fdd0,
|
||||||
|
0xf6c69a72a3989f5b,0x8aad549e57273d45,
|
||||||
|
0x9a3c2087a63f6399,0x36ac54e2f678864b,
|
||||||
|
0xc0cb28a98fcf3c7f,0x84576a1bb416a7dd,
|
||||||
|
0xf0fdf2d3f3c30b9f,0x656d44a2a11c51d5,
|
||||||
|
0x969eb7c47859e743,0x9f644ae5a4b1b325,
|
||||||
|
0xbc4665b596706114,0x873d5d9f0dde1fee,
|
||||||
|
0xeb57ff22fc0c7959,0xa90cb506d155a7ea,
|
||||||
|
0x9316ff75dd87cbd8,0x9a7f12442d588f2,
|
||||||
|
0xb7dcbf5354e9bece,0xc11ed6d538aeb2f,
|
||||||
|
0xe5d3ef282a242e81,0x8f1668c8a86da5fa,
|
||||||
|
0x8fa475791a569d10,0xf96e017d694487bc,
|
||||||
|
0xb38d92d760ec4455,0x37c981dcc395a9ac,
|
||||||
|
0xe070f78d3927556a,0x85bbe253f47b1417,
|
||||||
|
0x8c469ab843b89562,0x93956d7478ccec8e,
|
||||||
|
0xaf58416654a6babb,0x387ac8d1970027b2,
|
||||||
|
0xdb2e51bfe9d0696a,0x6997b05fcc0319e,
|
||||||
|
0x88fcf317f22241e2,0x441fece3bdf81f03,
|
||||||
|
0xab3c2fddeeaad25a,0xd527e81cad7626c3,
|
||||||
|
0xd60b3bd56a5586f1,0x8a71e223d8d3b074,
|
||||||
|
0x85c7056562757456,0xf6872d5667844e49,
|
||||||
|
0xa738c6bebb12d16c,0xb428f8ac016561db,
|
||||||
|
0xd106f86e69d785c7,0xe13336d701beba52,
|
||||||
|
0x82a45b450226b39c,0xecc0024661173473,
|
||||||
|
0xa34d721642b06084,0x27f002d7f95d0190,
|
||||||
|
0xcc20ce9bd35c78a5,0x31ec038df7b441f4,
|
||||||
|
0xff290242c83396ce,0x7e67047175a15271,
|
||||||
|
0x9f79a169bd203e41,0xf0062c6e984d386,
|
||||||
|
0xc75809c42c684dd1,0x52c07b78a3e60868,
|
||||||
|
0xf92e0c3537826145,0xa7709a56ccdf8a82,
|
||||||
|
0x9bbcc7a142b17ccb,0x88a66076400bb691,
|
||||||
|
0xc2abf989935ddbfe,0x6acff893d00ea435,
|
||||||
|
0xf356f7ebf83552fe,0x583f6b8c4124d43,
|
||||||
|
0x98165af37b2153de,0xc3727a337a8b704a,
|
||||||
|
0xbe1bf1b059e9a8d6,0x744f18c0592e4c5c,
|
||||||
|
0xeda2ee1c7064130c,0x1162def06f79df73,
|
||||||
|
0x9485d4d1c63e8be7,0x8addcb5645ac2ba8,
|
||||||
|
0xb9a74a0637ce2ee1,0x6d953e2bd7173692,
|
||||||
|
0xe8111c87c5c1ba99,0xc8fa8db6ccdd0437,
|
||||||
|
0x910ab1d4db9914a0,0x1d9c9892400a22a2,
|
||||||
|
0xb54d5e4a127f59c8,0x2503beb6d00cab4b,
|
||||||
|
0xe2a0b5dc971f303a,0x2e44ae64840fd61d,
|
||||||
|
0x8da471a9de737e24,0x5ceaecfed289e5d2,
|
||||||
|
0xb10d8e1456105dad,0x7425a83e872c5f47,
|
||||||
|
0xdd50f1996b947518,0xd12f124e28f77719,
|
||||||
|
0x8a5296ffe33cc92f,0x82bd6b70d99aaa6f,
|
||||||
|
0xace73cbfdc0bfb7b,0x636cc64d1001550b,
|
||||||
|
0xd8210befd30efa5a,0x3c47f7e05401aa4e,
|
||||||
|
0x8714a775e3e95c78,0x65acfaec34810a71,
|
||||||
|
0xa8d9d1535ce3b396,0x7f1839a741a14d0d,
|
||||||
|
0xd31045a8341ca07c,0x1ede48111209a050,
|
||||||
|
0x83ea2b892091e44d,0x934aed0aab460432,
|
||||||
|
0xa4e4b66b68b65d60,0xf81da84d5617853f,
|
||||||
|
0xce1de40642e3f4b9,0x36251260ab9d668e,
|
||||||
|
0x80d2ae83e9ce78f3,0xc1d72b7c6b426019,
|
||||||
|
0xa1075a24e4421730,0xb24cf65b8612f81f,
|
||||||
|
0xc94930ae1d529cfc,0xdee033f26797b627,
|
||||||
|
0xfb9b7cd9a4a7443c,0x169840ef017da3b1,
|
||||||
|
0x9d412e0806e88aa5,0x8e1f289560ee864e,
|
||||||
|
0xc491798a08a2ad4e,0xf1a6f2bab92a27e2,
|
||||||
|
0xf5b5d7ec8acb58a2,0xae10af696774b1db,
|
||||||
|
0x9991a6f3d6bf1765,0xacca6da1e0a8ef29,
|
||||||
|
0xbff610b0cc6edd3f,0x17fd090a58d32af3,
|
||||||
|
0xeff394dcff8a948e,0xddfc4b4cef07f5b0,
|
||||||
|
0x95f83d0a1fb69cd9,0x4abdaf101564f98e,
|
||||||
|
0xbb764c4ca7a4440f,0x9d6d1ad41abe37f1,
|
||||||
|
0xea53df5fd18d5513,0x84c86189216dc5ed,
|
||||||
|
0x92746b9be2f8552c,0x32fd3cf5b4e49bb4,
|
||||||
|
0xb7118682dbb66a77,0x3fbc8c33221dc2a1,
|
||||||
|
0xe4d5e82392a40515,0xfabaf3feaa5334a,
|
||||||
|
0x8f05b1163ba6832d,0x29cb4d87f2a7400e,
|
||||||
|
0xb2c71d5bca9023f8,0x743e20e9ef511012,
|
||||||
|
0xdf78e4b2bd342cf6,0x914da9246b255416,
|
||||||
|
0x8bab8eefb6409c1a,0x1ad089b6c2f7548e,
|
||||||
|
0xae9672aba3d0c320,0xa184ac2473b529b1,
|
||||||
|
0xda3c0f568cc4f3e8,0xc9e5d72d90a2741e,
|
||||||
|
0x8865899617fb1871,0x7e2fa67c7a658892,
|
||||||
|
0xaa7eebfb9df9de8d,0xddbb901b98feeab7,
|
||||||
|
0xd51ea6fa85785631,0x552a74227f3ea565,
|
||||||
|
0x8533285c936b35de,0xd53a88958f87275f,
|
||||||
|
0xa67ff273b8460356,0x8a892abaf368f137,
|
||||||
|
0xd01fef10a657842c,0x2d2b7569b0432d85,
|
||||||
|
0x8213f56a67f6b29b,0x9c3b29620e29fc73,
|
||||||
|
0xa298f2c501f45f42,0x8349f3ba91b47b8f,
|
||||||
|
0xcb3f2f7642717713,0x241c70a936219a73,
|
||||||
|
0xfe0efb53d30dd4d7,0xed238cd383aa0110,
|
||||||
|
0x9ec95d1463e8a506,0xf4363804324a40aa,
|
||||||
|
0xc67bb4597ce2ce48,0xb143c6053edcd0d5,
|
||||||
|
0xf81aa16fdc1b81da,0xdd94b7868e94050a,
|
||||||
|
0x9b10a4e5e9913128,0xca7cf2b4191c8326,
|
||||||
|
0xc1d4ce1f63f57d72,0xfd1c2f611f63a3f0,
|
||||||
|
0xf24a01a73cf2dccf,0xbc633b39673c8cec,
|
||||||
|
0x976e41088617ca01,0xd5be0503e085d813,
|
||||||
|
0xbd49d14aa79dbc82,0x4b2d8644d8a74e18,
|
||||||
|
0xec9c459d51852ba2,0xddf8e7d60ed1219e,
|
||||||
|
0x93e1ab8252f33b45,0xcabb90e5c942b503,
|
||||||
|
0xb8da1662e7b00a17,0x3d6a751f3b936243,
|
||||||
|
0xe7109bfba19c0c9d,0xcc512670a783ad4,
|
||||||
|
0x906a617d450187e2,0x27fb2b80668b24c5,
|
||||||
|
0xb484f9dc9641e9da,0xb1f9f660802dedf6,
|
||||||
|
0xe1a63853bbd26451,0x5e7873f8a0396973,
|
||||||
|
0x8d07e33455637eb2,0xdb0b487b6423e1e8,
|
||||||
|
0xb049dc016abc5e5f,0x91ce1a9a3d2cda62,
|
||||||
|
0xdc5c5301c56b75f7,0x7641a140cc7810fb,
|
||||||
|
0x89b9b3e11b6329ba,0xa9e904c87fcb0a9d,
|
||||||
|
0xac2820d9623bf429,0x546345fa9fbdcd44,
|
||||||
|
0xd732290fbacaf133,0xa97c177947ad4095,
|
||||||
|
0x867f59a9d4bed6c0,0x49ed8eabcccc485d,
|
||||||
|
0xa81f301449ee8c70,0x5c68f256bfff5a74,
|
||||||
|
0xd226fc195c6a2f8c,0x73832eec6fff3111,
|
||||||
|
0x83585d8fd9c25db7,0xc831fd53c5ff7eab,
|
||||||
|
0xa42e74f3d032f525,0xba3e7ca8b77f5e55,
|
||||||
|
0xcd3a1230c43fb26f,0x28ce1bd2e55f35eb,
|
||||||
|
0x80444b5e7aa7cf85,0x7980d163cf5b81b3,
|
||||||
|
0xa0555e361951c366,0xd7e105bcc332621f,
|
||||||
|
0xc86ab5c39fa63440,0x8dd9472bf3fefaa7,
|
||||||
|
0xfa856334878fc150,0xb14f98f6f0feb951,
|
||||||
|
0x9c935e00d4b9d8d2,0x6ed1bf9a569f33d3,
|
||||||
|
0xc3b8358109e84f07,0xa862f80ec4700c8,
|
||||||
|
0xf4a642e14c6262c8,0xcd27bb612758c0fa,
|
||||||
|
0x98e7e9cccfbd7dbd,0x8038d51cb897789c,
|
||||||
|
0xbf21e44003acdd2c,0xe0470a63e6bd56c3,
|
||||||
|
0xeeea5d5004981478,0x1858ccfce06cac74,
|
||||||
|
0x95527a5202df0ccb,0xf37801e0c43ebc8,
|
||||||
|
0xbaa718e68396cffd,0xd30560258f54e6ba,
|
||||||
|
0xe950df20247c83fd,0x47c6b82ef32a2069,
|
||||||
|
0x91d28b7416cdd27e,0x4cdc331d57fa5441,
|
||||||
|
0xb6472e511c81471d,0xe0133fe4adf8e952,
|
||||||
|
0xe3d8f9e563a198e5,0x58180fddd97723a6,
|
||||||
|
0x8e679c2f5e44ff8f,0x570f09eaa7ea7648,};
|
||||||
|
};
|
||||||
|
#endif // SIMDJSON_STATIC_REFLECTION
|
||||||
|
|
||||||
|
extern SIMDJSON_DLLIMPORTEXPORT const uint64_t power_of_five_128[651*2];
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace simdjson
|
} // namespace simdjson
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
#define SIMDJSON_IMPLEMENTATION lasx
|
#define SIMDJSON_IMPLEMENTATION lasx
|
||||||
|
#include <lsxintrin.h> // This is a hack. We should not need to put this include here.
|
||||||
|
#if SIMDJSON_CAN_ALWAYS_RUN_LASX
|
||||||
|
// nothing needed.
|
||||||
|
#else
|
||||||
|
SIMDJSON_TARGET_REGION("lasx,lsx")
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "simdjson/lasx/base.h"
|
#include "simdjson/lasx/base.h"
|
||||||
#include "simdjson/lasx/intrinsics.h"
|
#include "simdjson/lasx/intrinsics.h"
|
||||||
#include "simdjson/lasx/bitmanipulation.h"
|
#include "simdjson/lasx/bitmanipulation.h"
|
||||||
@@ -8,3 +15,5 @@
|
|||||||
#include "simdjson/lasx/stringparsing_defs.h"
|
#include "simdjson/lasx/stringparsing_defs.h"
|
||||||
|
|
||||||
#define SIMDJSON_SKIP_BACKSLASH_SHORT_CIRCUIT 1
|
#define SIMDJSON_SKIP_BACKSLASH_SHORT_CIRCUIT 1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef SIMDJSON_LASX_BUILDER_H
|
||||||
|
#define SIMDJSON_LASX_BUILDER_H
|
||||||
|
|
||||||
|
#include "simdjson/lasx/begin.h"
|
||||||
|
#include "simdjson/generic/builder/amalgamated.h"
|
||||||
|
#include "simdjson/lasx/end.h"
|
||||||
|
|
||||||
|
#endif // SIMDJSON_LASX_BUILDER_H
|
||||||
@@ -4,3 +4,10 @@
|
|||||||
|
|
||||||
#undef SIMDJSON_SKIP_BACKSLASH_SHORT_CIRCUIT
|
#undef SIMDJSON_SKIP_BACKSLASH_SHORT_CIRCUIT
|
||||||
#undef SIMDJSON_IMPLEMENTATION
|
#undef SIMDJSON_IMPLEMENTATION
|
||||||
|
|
||||||
|
|
||||||
|
#if SIMDJSON_CAN_ALWAYS_RUN_LASX
|
||||||
|
// nothing needed.
|
||||||
|
#else
|
||||||
|
SIMDJSON_UNTARGET_REGION
|
||||||
|
#endif
|
||||||
@@ -5,8 +5,7 @@
|
|||||||
#include "simdjson/lasx/base.h"
|
#include "simdjson/lasx/base.h"
|
||||||
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
|
|
||||||
// This should be the correct header whether
|
#include <lsxintrin.h>
|
||||||
// you use visual studio or other compilers.
|
|
||||||
#include <lasxintrin.h>
|
#include <lasxintrin.h>
|
||||||
|
|
||||||
static_assert(sizeof(__m256i) <= simdjson::SIMDJSON_PADDING, "insufficient padding for LoongArch ASX");
|
static_assert(sizeof(__m256i) <= simdjson::SIMDJSON_PADDING, "insufficient padding for LoongArch ASX");
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ using namespace simd;
|
|||||||
struct backslash_and_quote {
|
struct backslash_and_quote {
|
||||||
public:
|
public:
|
||||||
static constexpr uint32_t BYTES_PROCESSED = 32;
|
static constexpr uint32_t BYTES_PROCESSED = 32;
|
||||||
|
// We only copy if dst is non-null.
|
||||||
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
||||||
|
|
||||||
simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
|
simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
|
||||||
@@ -33,7 +34,9 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin
|
|||||||
// SIMDJSON_PADDING of padding
|
// SIMDJSON_PADDING of padding
|
||||||
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
|
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
|
||||||
simd8<uint8_t> v(src);
|
simd8<uint8_t> v(src);
|
||||||
v.store(dst);
|
if(dst != nullptr) {
|
||||||
|
v.store(dst);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
static_cast<uint32_t>((v == '\\').to_bitmask()), // bs_bits
|
static_cast<uint32_t>((v == '\\').to_bitmask()), // bs_bits
|
||||||
static_cast<uint32_t>((v == '"').to_bitmask()), // quote_bits
|
static_cast<uint32_t>((v == '"').to_bitmask()), // quote_bits
|
||||||
@@ -61,7 +64,7 @@ simdjson_inline escaping escaping::copy_and_find(const uint8_t *src, uint8_t *ds
|
|||||||
simd8<bool> is_backslash = (v == '\\');
|
simd8<bool> is_backslash = (v == '\\');
|
||||||
simd8<bool> is_control = (v < 32);
|
simd8<bool> is_control = (v < 32);
|
||||||
return {
|
return {
|
||||||
(is_backslash | is_quote | is_control).to_bitmask()
|
static_cast<uint64_t>((is_backslash | is_quote | is_control).to_bitmask())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef SIMDJSON_LSX_BUILDER_H
|
||||||
|
#define SIMDJSON_LSX_BUILDER_H
|
||||||
|
|
||||||
|
#include "simdjson/lsx/begin.h"
|
||||||
|
#include "simdjson/generic/builder/amalgamated.h"
|
||||||
|
#include "simdjson/lsx/end.h"
|
||||||
|
|
||||||
|
#endif // SIMDJSON_LSX_BUILDER_H
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
#include "simdjson/lsx/base.h"
|
#include "simdjson/lsx/base.h"
|
||||||
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
||||||
|
|
||||||
// This should be the correct header whether
|
|
||||||
// you use visual studio or other compilers.
|
|
||||||
#include <lsxintrin.h>
|
#include <lsxintrin.h>
|
||||||
|
|
||||||
static_assert(sizeof(__m128i) <= simdjson::SIMDJSON_PADDING, "insufficient padding for LoongArch SX");
|
static_assert(sizeof(__m128i) <= simdjson::SIMDJSON_PADDING, "insufficient padding for LoongArch SX");
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ using namespace simd;
|
|||||||
struct backslash_and_quote {
|
struct backslash_and_quote {
|
||||||
public:
|
public:
|
||||||
static constexpr uint32_t BYTES_PROCESSED = 32;
|
static constexpr uint32_t BYTES_PROCESSED = 32;
|
||||||
|
// We only copy if dst is non-null.
|
||||||
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
simdjson_inline backslash_and_quote copy_and_find(const uint8_t *src, uint8_t *dst);
|
||||||
|
|
||||||
simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
|
simdjson_inline bool has_quote_first() { return ((bs_bits - 1) & quote_bits) != 0; }
|
||||||
@@ -34,8 +35,10 @@ simdjson_inline backslash_and_quote backslash_and_quote::copy_and_find(const uin
|
|||||||
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
|
static_assert(SIMDJSON_PADDING >= (BYTES_PROCESSED - 1), "backslash and quote finder must process fewer than SIMDJSON_PADDING bytes");
|
||||||
simd8<uint8_t> v0(src);
|
simd8<uint8_t> v0(src);
|
||||||
simd8<uint8_t> v1(src + sizeof(v0));
|
simd8<uint8_t> v1(src + sizeof(v0));
|
||||||
v0.store(dst);
|
if(dst != nullptr) {
|
||||||
v1.store(dst + sizeof(v0));
|
v0.store(dst);
|
||||||
|
v1.store(dst + sizeof(v0));
|
||||||
|
}
|
||||||
|
|
||||||
// Getting a 64-bit bitmask is much cheaper than multiple 16-bit bitmasks on LSX; therefore, we
|
// Getting a 64-bit bitmask is much cheaper than multiple 16-bit bitmasks on LSX; therefore, we
|
||||||
// smash them together into a 64-byte mask and get the bitmask from there.
|
// smash them together into a 64-byte mask and get the bitmask from there.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "simdjson/padded_string_view-inl.h"
|
#include "simdjson/padded_string_view-inl.h"
|
||||||
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
#include <cwchar>
|
||||||
|
|
||||||
namespace simdjson {
|
namespace simdjson {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
@@ -125,6 +126,33 @@ inline const char *padded_string::data() const noexcept { return data_ptr; }
|
|||||||
|
|
||||||
inline char *padded_string::data() noexcept { return data_ptr; }
|
inline char *padded_string::data() noexcept { return data_ptr; }
|
||||||
|
|
||||||
|
inline bool padded_string::append(const char *data, size_t length) noexcept {
|
||||||
|
if (length == 0) {
|
||||||
|
return true; // Nothing to append
|
||||||
|
}
|
||||||
|
size_t new_size = viable_size + length;
|
||||||
|
if (new_size < viable_size) {
|
||||||
|
// Overflow, cannot append
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
char *new_data_ptr = internal::allocate_padded_buffer(new_size);
|
||||||
|
if (new_data_ptr == nullptr) {
|
||||||
|
// Allocation failed, cannot append
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Copy existing data
|
||||||
|
if (viable_size > 0) {
|
||||||
|
std::memcpy(new_data_ptr, data_ptr, viable_size);
|
||||||
|
}
|
||||||
|
// Copy new data
|
||||||
|
std::memcpy(new_data_ptr + viable_size, data, length);
|
||||||
|
// Update
|
||||||
|
delete[] data_ptr;
|
||||||
|
data_ptr = new_data_ptr;
|
||||||
|
viable_size = new_size;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
inline padded_string::operator std::string_view() const simdjson_lifetime_bound { return std::string_view(data(), length()); }
|
inline padded_string::operator std::string_view() const simdjson_lifetime_bound { return std::string_view(data(), length()); }
|
||||||
|
|
||||||
inline padded_string::operator padded_string_view() const noexcept simdjson_lifetime_bound {
|
inline padded_string::operator padded_string_view() const noexcept simdjson_lifetime_bound {
|
||||||
@@ -185,6 +213,159 @@ inline simdjson_result<padded_string> padded_string::load(std::string_view filen
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(_WIN32) && SIMDJSON_CPLUSPLUS17
|
||||||
|
inline simdjson_result<padded_string> padded_string::load(std::wstring_view filename) noexcept {
|
||||||
|
// Open the file using the wide characters
|
||||||
|
SIMDJSON_PUSH_DISABLE_WARNINGS
|
||||||
|
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
|
||||||
|
std::FILE *fp = _wfopen(filename.data(), L"rb");
|
||||||
|
SIMDJSON_POP_DISABLE_WARNINGS
|
||||||
|
|
||||||
|
if (fp == nullptr) {
|
||||||
|
return IO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the file size
|
||||||
|
int ret;
|
||||||
|
#if SIMDJSON_VISUAL_STUDIO && !SIMDJSON_IS_32BITS
|
||||||
|
ret = _fseeki64(fp, 0, SEEK_END);
|
||||||
|
#else
|
||||||
|
ret = std::fseek(fp, 0, SEEK_END);
|
||||||
|
#endif // _WIN64
|
||||||
|
if(ret < 0) {
|
||||||
|
std::fclose(fp);
|
||||||
|
return IO_ERROR;
|
||||||
|
}
|
||||||
|
#if SIMDJSON_VISUAL_STUDIO && !SIMDJSON_IS_32BITS
|
||||||
|
__int64 llen = _ftelli64(fp);
|
||||||
|
if(llen == -1L) {
|
||||||
|
std::fclose(fp);
|
||||||
|
return IO_ERROR;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
long llen = std::ftell(fp);
|
||||||
|
if((llen < 0) || (llen == LONG_MAX)) {
|
||||||
|
std::fclose(fp);
|
||||||
|
return IO_ERROR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Allocate the padded_string
|
||||||
|
size_t len = static_cast<size_t>(llen);
|
||||||
|
padded_string s(len);
|
||||||
|
if (s.data() == nullptr) {
|
||||||
|
std::fclose(fp);
|
||||||
|
return MEMALLOC;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the padded_string
|
||||||
|
std::rewind(fp);
|
||||||
|
size_t bytes_read = std::fread(s.data(), 1, len, fp);
|
||||||
|
if (std::fclose(fp) != 0 || bytes_read != len) {
|
||||||
|
return IO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// padded_string_builder implementations
|
||||||
|
|
||||||
|
inline padded_string_builder::padded_string_builder() noexcept = default;
|
||||||
|
|
||||||
|
inline padded_string_builder::padded_string_builder(size_t new_capacity) noexcept {
|
||||||
|
if (new_capacity > 0) {
|
||||||
|
data = internal::allocate_padded_buffer(new_capacity);
|
||||||
|
if (data != nullptr) {
|
||||||
|
this->capacity = new_capacity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline padded_string_builder::padded_string_builder(padded_string_builder &&o) noexcept
|
||||||
|
: size(o.size), capacity(o.capacity), data(o.data) {
|
||||||
|
o.size = 0;
|
||||||
|
o.capacity = 0;
|
||||||
|
o.data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline padded_string_builder &padded_string_builder::operator=(padded_string_builder &&o) noexcept {
|
||||||
|
if (this != &o) {
|
||||||
|
delete[] data;
|
||||||
|
size = o.size;
|
||||||
|
capacity = o.capacity;
|
||||||
|
data = o.data;
|
||||||
|
o.size = 0;
|
||||||
|
o.capacity = 0;
|
||||||
|
o.data = nullptr;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline padded_string_builder::~padded_string_builder() noexcept {
|
||||||
|
delete[] data;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool padded_string_builder::append(const char *newdata, size_t length) noexcept {
|
||||||
|
if (length == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!reserve(length)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::memcpy(data + size, newdata, length);
|
||||||
|
size += length;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool padded_string_builder::append(std::string_view sv) noexcept {
|
||||||
|
return append(sv.data(), sv.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline size_t padded_string_builder::length() const noexcept {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline padded_string padded_string_builder::build() const noexcept {
|
||||||
|
return padded_string(data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline padded_string padded_string_builder::convert() noexcept {
|
||||||
|
padded_string result{};
|
||||||
|
result.data_ptr = data;
|
||||||
|
result.viable_size = size;
|
||||||
|
data = nullptr;
|
||||||
|
size = 0;
|
||||||
|
capacity = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool padded_string_builder::reserve(size_t additional) noexcept {
|
||||||
|
size_t needed = size + additional;
|
||||||
|
if (needed <= capacity) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
size_t new_capacity = needed;
|
||||||
|
// We are going to grow the capacity exponentially to avoid
|
||||||
|
// repeated allocations.
|
||||||
|
if (new_capacity < 4096) {
|
||||||
|
new_capacity *= 2;
|
||||||
|
} else {
|
||||||
|
new_capacity += new_capacity/2; // grow by 1.5x
|
||||||
|
}
|
||||||
|
char *new_data = internal::allocate_padded_buffer(new_capacity);
|
||||||
|
if (new_data == nullptr) {
|
||||||
|
return false; // Allocation failed
|
||||||
|
}
|
||||||
|
if (size > 0) {
|
||||||
|
std::memcpy(new_data, data, size);
|
||||||
|
}
|
||||||
|
delete[] data;
|
||||||
|
data = new_data;
|
||||||
|
capacity = new_capacity;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace simdjson
|
} // namespace simdjson
|
||||||
|
|
||||||
inline simdjson::padded_string operator ""_padded(const char *str, size_t len) {
|
inline simdjson::padded_string operator ""_padded(const char *str, size_t len) {
|
||||||
@@ -192,7 +373,7 @@ inline simdjson::padded_string operator ""_padded(const char *str, size_t len) {
|
|||||||
}
|
}
|
||||||
#ifdef __cpp_char8_t
|
#ifdef __cpp_char8_t
|
||||||
inline simdjson::padded_string operator ""_padded(const char8_t *str, size_t len) {
|
inline simdjson::padded_string operator ""_padded(const char8_t *str, size_t len) {
|
||||||
return simdjson::padded_string(reinterpret_cast<const char8_t *>(str), len);
|
return simdjson::padded_string(reinterpret_cast<const char *>(str), len);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif // SIMDJSON_PADDED_STRING_INL_H
|
#endif // SIMDJSON_PADDED_STRING_INL_H
|
||||||
|
|||||||
@@ -98,6 +98,16 @@ struct padded_string final {
|
|||||||
**/
|
**/
|
||||||
char *data() noexcept;
|
char *data() noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append data to the padded string. Return true on success, false on failure.
|
||||||
|
* The complexity is O(n) where n is the new size of the string. If you are
|
||||||
|
* doing multiple appends, consider using padded_string_builder for better performance.
|
||||||
|
*
|
||||||
|
* @param data the buffer to append
|
||||||
|
* @param length the number of bytes to append
|
||||||
|
*/
|
||||||
|
inline bool append(const char *data, size_t length) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a std::string_view with the same content.
|
* Create a std::string_view with the same content.
|
||||||
*/
|
*/
|
||||||
@@ -127,7 +137,21 @@ struct padded_string final {
|
|||||||
**/
|
**/
|
||||||
inline static simdjson_result<padded_string> load(std::string_view path) noexcept;
|
inline static simdjson_result<padded_string> load(std::string_view path) noexcept;
|
||||||
|
|
||||||
|
#if defined(_WIN32) && SIMDJSON_CPLUSPLUS17
|
||||||
|
/**
|
||||||
|
* This function accepts a wide string path (UTF-16) and converts it to
|
||||||
|
* UTF-8 before loading the file. This allows windows users to work
|
||||||
|
* with unicode file paths without manually converting the paths every time.
|
||||||
|
*
|
||||||
|
* @return IO_ERROR on error, including conversion failures.
|
||||||
|
*
|
||||||
|
* @param path the path to the file as a wide string.
|
||||||
|
**/
|
||||||
|
inline static simdjson_result<padded_string> load(std::wstring_view path) noexcept;
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class padded_string_builder;
|
||||||
padded_string &operator=(const padded_string &o) = delete;
|
padded_string &operator=(const padded_string &o) = delete;
|
||||||
padded_string(const padded_string &o) = delete;
|
padded_string(const padded_string &o) = delete;
|
||||||
|
|
||||||
@@ -136,6 +160,101 @@ private:
|
|||||||
|
|
||||||
}; // padded_string
|
}; // padded_string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder for constructing padded_string incrementally.
|
||||||
|
*
|
||||||
|
* This class allows efficient appending of data and then building a padded_string.
|
||||||
|
*/
|
||||||
|
class padded_string_builder {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Create a new, empty padded string builder.
|
||||||
|
*/
|
||||||
|
inline padded_string_builder() noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new padded string builder with initial capacity.
|
||||||
|
*
|
||||||
|
* @param capacity the initial capacity of the builder.
|
||||||
|
*/
|
||||||
|
inline padded_string_builder(size_t capacity) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move constructor.
|
||||||
|
*/
|
||||||
|
inline padded_string_builder(padded_string_builder &&o) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move assignment.
|
||||||
|
*/
|
||||||
|
inline padded_string_builder &operator=(padded_string_builder &&o) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy constructor (deleted).
|
||||||
|
*/
|
||||||
|
padded_string_builder(const padded_string_builder &) = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy assignment (deleted).
|
||||||
|
*/
|
||||||
|
padded_string_builder &operator=(const padded_string_builder &) = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor.
|
||||||
|
*/
|
||||||
|
inline ~padded_string_builder() noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append data to the builder.
|
||||||
|
*
|
||||||
|
* @param newdata the buffer to append
|
||||||
|
* @param length the number of bytes to append
|
||||||
|
* @return true if the append succeeded, false if allocation failed
|
||||||
|
*/
|
||||||
|
inline bool append(const char *newdata, size_t length) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append a string view to the builder.
|
||||||
|
*
|
||||||
|
* @param sv the string view to append
|
||||||
|
* @return true if the append succeeded, false if allocation failed
|
||||||
|
*/
|
||||||
|
inline bool append(std::string_view sv) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current length of the built string.
|
||||||
|
*/
|
||||||
|
inline size_t length() const noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a padded_string from the current content. The builder's content
|
||||||
|
* is not modified. If you want to avoid the copy, use convert() instead.
|
||||||
|
*
|
||||||
|
* @return a padded_string containing a copy of the built content.
|
||||||
|
*/
|
||||||
|
inline padded_string build() const noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the current content into a padded_string. The
|
||||||
|
* builder's content is emptied, the capacity is lost.
|
||||||
|
*
|
||||||
|
* @return a padded_string containing the built content.
|
||||||
|
*/
|
||||||
|
inline padded_string convert() noexcept;
|
||||||
|
private:
|
||||||
|
size_t size{0};
|
||||||
|
size_t capacity{0};
|
||||||
|
char *data{nullptr};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure the builder has enough capacity.
|
||||||
|
*
|
||||||
|
* @param additional the additional capacity needed.
|
||||||
|
* @return true if the reservation succeeded, false if allocation failed
|
||||||
|
*/
|
||||||
|
inline bool reserve(size_t additional) noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send padded_string instance to an output stream.
|
* Send padded_string instance to an output stream.
|
||||||
*
|
*
|
||||||
|
|||||||