mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
910f272467
* Make architecture implementations virtual functions - Easier to add new architectures (add implementation to implementation.cpp) - Easier to add new algorithms / functions to architecture selection (add to implementation.h, implement) - Automatically select best implementation in static initialization - Allow user to explicitly select implementation with a string (i.e. parameter) - Allow user to inspect current implementation name/description - Allow user to list available implementations - Eliminate architecture enum and architecture-based templating - Add noexcept in non-inline functions * Move implementation static methods to their own classes * Detect best supported implementation on first use * available_implementationsI() -> available_implementations
63 lines
2.5 KiB
C++
63 lines
2.5 KiB
C++
// TODO Remove this -- deprecated API and files
|
|
|
|
#ifndef SIMDJSON_JSONPARSER_H
|
|
#define SIMDJSON_JSONPARSER_H
|
|
|
|
#include "simdjson/document.h"
|
|
#include "simdjson/parsedjson.h"
|
|
#include "simdjson/jsonioutil.h"
|
|
|
|
namespace simdjson {
|
|
|
|
//
|
|
// C API (json_parse and build_parsed_json) declarations
|
|
//
|
|
|
|
inline int json_parse(const uint8_t *buf, size_t len, document::parser &parser, bool realloc_if_needed = true) noexcept {
|
|
error_code code = parser.parse(buf, len, realloc_if_needed).error;
|
|
// The deprecated json_parse API is a signal that the user plans to *use* the error code / valid
|
|
// bits in the parser instead of heeding the result code. The normal parser unsets those in
|
|
// anticipation of making the error code ephemeral.
|
|
// Here we put the code back into the parser, until we've removed this method.
|
|
parser.valid = code == SUCCESS;
|
|
parser.error = code;
|
|
return code;
|
|
}
|
|
inline int json_parse(const char *buf, size_t len, document::parser &parser, bool realloc_if_needed = true) noexcept {
|
|
return json_parse(reinterpret_cast<const uint8_t *>(buf), len, parser, realloc_if_needed);
|
|
}
|
|
inline int json_parse(const std::string &s, document::parser &parser, bool realloc_if_needed = true) noexcept {
|
|
return json_parse(s.data(), s.length(), parser, realloc_if_needed);
|
|
}
|
|
inline int json_parse(const padded_string &s, document::parser &parser) noexcept {
|
|
return json_parse(s.data(), s.length(), parser, false);
|
|
}
|
|
|
|
WARN_UNUSED static document::parser build_parsed_json(const uint8_t *buf, size_t len, bool realloc_if_needed = true) noexcept {
|
|
document::parser parser;
|
|
if (!parser.allocate_capacity(len)) {
|
|
parser.valid = false;
|
|
parser.error = MEMALLOC;
|
|
return parser;
|
|
}
|
|
json_parse(buf, len, parser, realloc_if_needed);
|
|
return parser;
|
|
}
|
|
WARN_UNUSED inline document::parser build_parsed_json(const char *buf, size_t len, bool realloc_if_needed = true) noexcept {
|
|
return build_parsed_json(reinterpret_cast<const uint8_t *>(buf), len, realloc_if_needed);
|
|
}
|
|
WARN_UNUSED inline document::parser build_parsed_json(const std::string &s, bool realloc_if_needed = true) noexcept {
|
|
return build_parsed_json(s.data(), s.length(), realloc_if_needed);
|
|
}
|
|
WARN_UNUSED inline document::parser build_parsed_json(const padded_string &s) noexcept {
|
|
return build_parsed_json(s.data(), s.length(), false);
|
|
}
|
|
|
|
// We do not want to allow implicit conversion from C string to std::string.
|
|
int json_parse(const char *buf, document::parser &parser) noexcept = delete;
|
|
document::parser build_parsed_json(const char *buf) noexcept = delete;
|
|
|
|
} // namespace simdjson
|
|
|
|
#endif
|