feat(reflect): add reflection-based tree serializer with format-agnostic SerdeBase - #71
Merged
Merged
Conversation
- temporary default JSON implementation
…rializer - build a SerdeStruct tree first, then render through format hooks (Json/Xml/Toml) - store format-neutral raw values in SerdeNode; add read accessors + SerdeStruct::root() - extend reflection getter/setter/deduce_type to support Array/Map members - add Json example with output assertion in test_serdebase
- optimize code for better performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gkit::core::reflect: an object isexpanded into a format-neutral tree (
SerdeStruct/SerdeNode), then rendered to atarget text format through the pure-virtual
SerdeBaseinterface.Jsonexample (in tests) demonstrates extensibility; Xml/Toml can be added byoverriding the wrapper/gap hooks.
Changes
seralize.{hpp,cpp}):SerdeStruct(ObjectId)/(Value)builds aSerdeNodetree (Object/Array/Map/basic) viaClassInfo::for_each_field+get_field, with recursive nesting.SerdeNodestores format-neutral raw leaf values and exposesget_key/get_val/get_type/get_children;SerdeStruct::root().serdebase.{hpp,cpp}): template methodseralize(ObjectId)/seralize(key, Value)builds the tree and renders it through 9 pure-virtual hooks (key_wrapper,kv_connect, container wrappers, element gaps,value_wrapper). Virtual destructor; all hooks= 0(also resolves the undefined-vtable link error).make_getter/make_setter/deduce_typenow supportArray/Mapobject members (previously fell through toNull).seralize.cpp+serdebase.cppinsrc/core/CMakeLists.txt.test_serdebase.cppdefines aJsonsubclass and asserts exact output (incl. nested array/map);test_seralize.cppcovers object-to-tree output. The temporarySerdeStruct::to_string()was removed in favor ofSerdeBase.Verification
test_serdebaseandtest_seralizeboth build and pass:{"num":10,"f_num":20.000000,"str":"Hello my girl","arr":100,200,300,"map" {"map_fnum":200.000000,"map_num":100,"map_str":""}}
Follow-ups
serdebase.hpp(public) includes the privatecore/reflect/seralize.hpp; promote thetree types to
include/gkit/onceSerdeStructleaves its temporary state.deserialize) not implemented yet;SerdeStruct(const Value)remainsdeclared but undefined.