nodesource/rapidjson-writable

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

rapidjson-writable build status

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);

Testing Manually
Dump Tokens
 clean && make test_dump

n/test_dump file.json

file.json | ./bin/test_dump

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.