Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writer object should be reusable and do validation by assertion #66

Closed
miloyip opened this issue Jul 12, 2014 · 2 comments
Closed

Writer object should be reusable and do validation by assertion #66

miloyip opened this issue Jul 12, 2014 · 2 comments
Milestone

Comments

@miloyip
Copy link
Collaborator

miloyip commented Jul 12, 2014

Writer should always produce well-formed JSON. Invalid sequence of events should be detected via assertion. However, currently generating two or more JSONs into output stream does not generate assertion fail. For example,

Writer<Stream> writer(stream);
writer.StartObject();
writer.EndObject();
writer.StartObject();
writer.EndObject();

Will output {}{} to the stream.

I suggest that an explicitly reset API should be added:

Writer<Stream> writer(stream);
writer.StartObject();
writer.EndObject();
writer.Reset(newStream);
writer.StartObject();
writer.EndObject();

So that, error of multiple root elements can be detected, and also Writer object can be reused. The advantage of reusing an Writer object is to prevent reallocating memory for Writer's internal data structure (basically a stack).

@miloyip miloyip added this to the v1.0 Beta milestone Jul 12, 2014
@miloyip
Copy link
Collaborator Author

miloyip commented Jul 12, 2014

Writer::Double() should detect NaN and +/-inf as well (via assert). These are not valid JSON number in the standard.

@miloyip
Copy link
Collaborator Author

miloyip commented Jul 12, 2014

There is a locale issue in up-stream as well. https://code.google.com/p/rapidjson/issues/detail?id=84

miloyip added a commit that referenced this issue Jul 13, 2014
Note it redefines RAPIDJSON_ASSERT() to throw exception in unittest and
check for assertion with gtest.
@miloyip miloyip closed this as completed Jul 13, 2014
miloyip added a commit that referenced this issue Jul 15, 2014
Fix #66 by adding Writer::Reset() and Writer::IsComplete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant