deploy: 4155e2938f
This commit is contained in:
1 parent
be4d0a6f4b
commit
90f0c9d411
714 files changed
+22067
-622
No files matched your search
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <nlohmann/json_view.hpp>
|
||||
|
||||
using json_document = nlohmann::json_document;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << std::boolalpha;
|
||||
|
||||
std::vector<std::string> messages =
|
||||
{
|
||||
R"({"id": 1})", R"({"id": 2, "tag": "x"})", R"({"id": 3})"
|
||||
};
|
||||
|
||||
// parse into the same document over and over: its node index and decode
|
||||
// buffer are reused instead of being freed and reallocated for each message
|
||||
json_document doc;
|
||||
std::size_t total = 0;
|
||||
for (const auto& msg : messages)
|
||||
{
|
||||
doc.read(msg);
|
||||
total += doc.root().size();
|
||||
}
|
||||
std::cout << total << '\n';
|
||||
|
||||
// read() can also change what kind of input is owned/borrowed between calls
|
||||
doc.read(std::string(R"({"owned": true})"));
|
||||
std::cout << doc.owns_source() << '\n';
|
||||
}
|
||||
Reference in new issue
Block a user