mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-02-02 01:06:41 +08:00
Signed-off-by: yah01 <yang.cen@zilliz.com>
This commit is contained in:
parent
65f4e4c5fb
commit
720bbd7945
@ -29,6 +29,12 @@
|
||||
|
||||
#include "exceptions/EasyAssert.h"
|
||||
#include "simdjson.h"
|
||||
#include "simdjson/common_defs.h"
|
||||
#include "simdjson/dom/array.h"
|
||||
#include "simdjson/dom/document.h"
|
||||
#include "simdjson/dom/element.h"
|
||||
#include "simdjson/error.h"
|
||||
#include "simdjson/padded_string.h"
|
||||
|
||||
namespace milvus {
|
||||
using document = simdjson::ondemand::document;
|
||||
@ -99,6 +105,18 @@ class Json {
|
||||
return doc;
|
||||
}
|
||||
|
||||
value_result<simdjson::dom::element>
|
||||
dom_doc() const {
|
||||
thread_local simdjson::dom::parser parser;
|
||||
|
||||
// it's always safe to add the padding,
|
||||
// as we have allocated the memory with this padding
|
||||
auto doc = parser.parse(data_);
|
||||
AssertInfo(doc.error() == simdjson::SUCCESS, std::string("failed to parse the json ") + data_.data() + ": " +
|
||||
simdjson::error_message(doc.error()));
|
||||
return doc;
|
||||
}
|
||||
|
||||
bool
|
||||
exist(std::string_view pointer) const {
|
||||
return doc().at_pointer(pointer).error() == simdjson::SUCCESS;
|
||||
@ -120,6 +138,15 @@ class Json {
|
||||
return doc().at_pointer(pointer).get<T>();
|
||||
}
|
||||
|
||||
// get dom array by JSON pointer,
|
||||
// call `size()` to get array size,
|
||||
// call `at()` to get array element by index,
|
||||
// iterate through array elements by iterator.
|
||||
value_result<simdjson::dom::array>
|
||||
array_at(std::string_view pointer) const {
|
||||
return dom_doc().at_pointer(pointer).get_array();
|
||||
}
|
||||
|
||||
std::string_view
|
||||
data() const {
|
||||
return data_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user