Name: rapidjson-writable
Owner: NodeSource
Description: API to rapidjson that supports writing data asynchronously. Uses libuv to block the parser thread while waiting for data.
Created: 2017-11-29 21:45:02.0
Updated: 2017-12-24 23:44:55.0
Pushed: 2017-12-22 17:04:50.0
Homepage: null
Size: 48
Language: C++
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
API to rapidjson that supports writing data asynchronously. Uses libuv to block the parser thread while waiting for data.
lude <iostream>
lude <fstream>
lude <unistd.h>
ine CHUNK_SIZE 64
lude "test_assert.h" // see test/test_assert.h
lude "util.h" // see test/util.h
lude "rapidjson_writable.h"
g namespace rapidjson_writable;
s DumpWritable : public RapidjsonWritable {
id onparserFailure(rapidjson::Reader& reader) {
printParserFailure(reader);
id onparsedToken(SaxHandler& handler) {
printParsedToken(handler);
id onparseComplete() {
fprintf(stdout, "OK\n");
write_chunks(std::istream& stream, RapidjsonWritable& writable) {
{
std::vector<char> buffer (CHUNK_SIZE, 0);
stream.read(buffer.data(), buffer.size());
writable.write(*buffer.data(), buffer.size());
usleep(1E5);
while(!stream.eof());
wait for parser thread to finish before exiting
itable.wait();
main(int argc, const char* argv[]) {
mpWritable writable;
sert(!writable.initialized());
nst TestWritableResult* r = writable.init(TestWritableResult::OK());
(r->hasError) {
fprintf(stderr, "Encountered writable init error: %s\n", r->errorMsg);
delete r;
return 1;
lete r;
sert(writable.initialized());
nst char* file = argv[1];
d::ifstream ifs(file);
ite_chunks(ifs, writable);
clean && make test_dump
n/test_dump file.json
file.json | ./bin/test_dump