p4c icon indicating copy to clipboard operation
p4c copied to clipboard

JSONGenerator/Loader cleanups

Open ChrisDodd opened this issue 10 months ago • 0 comments

In trying to use the JSONGenerator/Loader code for additional things, I found a number of ways in which they are tricky to use and easy to use incorrectly (as well as some ways they are used incorrectly), mostly due to having exposed internals. So I made all those internals private and provided a cleaner interface to be used

  • JSONGenerator now uses emit methods to output values (rather than allowing << arbitrary text which was erro prone), and ensures that objects only contain key-value pairs and vector only contain values (no keys) and things match up properly.
  • JSONLoader now provides is tester methods for checking that values are the expected type, and manages its internal memory with unique_ptr so as to not require the garbage collector.

ChrisDodd avatar Feb 24 '25 01:02 ChrisDodd