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

Allow no indentation output of JSON and XML #64

Closed
mattyclarkson opened this issue Feb 26, 2014 · 8 comments
Closed

Allow no indentation output of JSON and XML #64

mattyclarkson opened this issue Feb 26, 2014 · 8 comments
Milestone

Comments

@mattyclarkson
Copy link
Contributor

rapidxml and rapidjson both support output without any indentation which can save valuable bytes if sending the JSON or XML over the network. It would be create if the XML and JSON archives could support output with no indentation.

@mattyclarkson
Copy link
Contributor Author

I'm happy to help with patches/pull request for this.

@AzothAmmo
Copy link
Contributor

I have no problem with this if it is added as a parameter to the constructors of these archives. I assume that both rapidxml and rapidjson can parse either format without being told it has no indentation, right?

If you look into this, are there any other parameters for these libraries worth exposing?

@mattyclarkson
Copy link
Contributor Author

print_no_indenting is currently the only flag that rapidxml has and rapidjson is just a matter of switching to Writer over PrettyWriter. There could be more flags in the future, so may as well prepare for it:

JSONOutputArchive(std::ostream & stream, int precision = 20)

XMLOutputArchive(std::ostream & stream, size_t precision = 20, bool outputType = false )

to

enum Flags {  // Not sure of your style for enums.
  no_flags  ///< No special modifiers for the output archive
}
JSONOutputArchive(std::ostream & stream, int precision = 20, size_t indentation = 4, int flags = no_flags)

enum class Flags {  // Not sure of your style for enums.
  none,  ///< No special modifiers for the output archive
  addType  ///< Adds the object typename to the XML node
}
XMLOutputArchive(std::ostream & stream, int precision = 20, size_t indentation = 4, int flags = no_flags)

This breaks the API though 👎 but makes it consistent 👍

@AzothAmmo
Copy link
Contributor

We're already making some breaking changes for 1.0 so this isn't an issue.

@AzothAmmo AzothAmmo added this to the v1.0.0 milestone Feb 26, 2014
@mattyclarkson
Copy link
Contributor Author

Hit some pretty bad timing with suggesting this - I'm about to go skiing for two weeks. Might not have a pull request ready until after that, sorry. 😒

@AzothAmmo
Copy link
Contributor

Debating a few ways of implementing this, all of which come down to pointless style differences.

The method I am favoring right now would make the constructors look something like:

JSONOutputArchive(std::ostream & stream, Options const & options = Options::Default())

Where Options is a nested struct in each archive. My only problem with using bit flags for options is that any option that requires a parameter still needs to be in the argument list. RapidXML is only a binary flag for indent vs no indent, but RapidJSON allows for specifying the number (and type) of character. Using this scheme we could also offer pre-defined option types for the most common things, like Options::NoIndent() would return an Options object with all default parameters and indentation turned off.

Ultimately I expect few users to use these options so I want a solution that is as clean as possible without bloating up the code too much.

AzothAmmo added a commit that referenced this issue Mar 14, 2014
AzothAmmo added a commit that referenced this issue Mar 14, 2014
@AzothAmmo
Copy link
Contributor

Done done done.

AzothAmmo added a commit that referenced this issue Mar 14, 2014
@mattyclarkson
Copy link
Contributor Author

Cool, thanks for implementing this 😄

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

2 participants