Closed liuzicheng1987 closed 6 months ago
I personally don't think the Writer and Reader interfaces (with associated Parser) don't provide the clearest and flexible approach - especially in comparison to Rust Serdes design. Even though Rust native traits don't have a natural match in cpp we could strive a similar approach.
@jimixxperez, would that mean that the users of our library would have to inherit some base class from our library? Or how would users then implement the "traits" on their structs?
The Reader and Writer have been designed with various JSON libraries in mind. Whereas the design for Reader seems fine, the Writer needs an update.
The problem is that many libraries for binary formats require you to directly assign children to their parents as opposed to first creating the children and then assigning them to their parents.
For instance, pugixml requires you to do this:
Likewise, libbson (https://mongoc.org/libbson/current/creating.html):
The current workaround it to have structures like OutputArray and OutputObject (https://github.com/getml/reflect-cpp/blob/f/xml/include/rfl/flexbuf/OutputArray.hpp). This works well, but it adds an unnecessary extra layer and runtime overhead.
This could be avoided by a redesign of the writer that takes these limitations into account.