Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Conversation

@igorpeshansky
Copy link
Contributor

No description provided.

Return the number of bytes processed from ParseStream.
Add more tests.
src/json.cc Outdated
size_t total_bytes_consumed = 0;
yajl_handle& handle = state_->handle();

for (;;) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would while (!stream.eof()) { be more concise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would; also in line 446. It didn't use to be the case, but after an earlier series of refactorings of that code, the loop ended up being simple enough. Done.

" \"ba"
));
p.ParseStream(std::istringstream(
"r\": {\"x\": 0, \"y\": nu"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to spend a minute or two to reason about the indentation you've chosen. I don't think it's incredibly useful to preserve the location based on where you left off on the previous line. If you feel strongly about it, I'd say keep it, but otherwise, consistent indentations would have been easier for my brain to parse as you have the final json encoded check that makes it clear what the entire json blob represents.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make it clear that the stream literally stops in the middle of a token, which may not be obvious from the test name. I think it's important enough to call out, and indentation works better than comments, IMO. Let's stick with this for now — we can always do a cleanup pass later.

src/json.cc Outdated
}

size_t bytes = yajl_get_bytes_consumed(handle);
std::cerr << "Consumed " << bytes << " out of chunk " << count << " from '" << str << "'" << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not on an error code path - why log to std::cerr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, these were in an earlier commit, and were removed in the next one.

src/json.cc Outdated

size_t bytes = yajl_get_bytes_consumed(handle);
std::string str((const char*)data, bytes);
std::cerr << "Consumed stream " << bytes << ": '" << str << "'" << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, these were in an earlier commit, and were removed in the next one.

Copy link
Contributor Author

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL.

src/json.cc Outdated
size_t total_bytes_consumed = 0;
yajl_handle& handle = state_->handle();

for (;;) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would; also in line 446. It didn't use to be the case, but after an earlier series of refactorings of that code, the loop ended up being simple enough. Done.

" \"ba"
));
p.ParseStream(std::istringstream(
"r\": {\"x\": 0, \"y\": nu"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make it clear that the stream literally stops in the middle of a token, which may not be obvious from the test name. I think it's important enough to call out, and indentation works better than comments, IMO. Let's stick with this for now — we can always do a cleanup pass later.

src/json.cc Outdated
}

size_t bytes = yajl_get_bytes_consumed(handle);
std::cerr << "Consumed " << bytes << " out of chunk " << count << " from '" << str << "'" << std::endl;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, these were in an earlier commit, and were removed in the next one.

src/json.cc Outdated

size_t bytes = yajl_get_bytes_consumed(handle);
std::string str((const char*)data, bytes);
std::cerr << "Consumed stream " << bytes << ": '" << str << "'" << std::endl;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, these were in an earlier commit, and were removed in the next one.

Copy link
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@igorpeshansky
Copy link
Contributor Author

@sparkprime LGTM'd offline. Merging.

@igorpeshansky igorpeshansky merged commit f5d0be0 into master Mar 30, 2018
@igorpeshansky igorpeshansky deleted the igorp-json-streaming-parser branch March 30, 2018 20:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants