Skip to content

feat(reflect): add reflection-based tree serializer with format-agnostic SerdeBase - #71

Merged
CoraBlack merged 13 commits into
gkit-org:mainfrom
CoraBlack:feature/seralize
Aug 3, 2026
Merged

CoraBlack merged 13 commits into
gkit-org:mainfrom
CoraBlack:feature/seralize

Conversation

@CoraBlack

@CoraBlack CoraBlack commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add a reflection-driven object serializer to gkit::core::reflect: an object is
    expanded into a format-neutral tree (SerdeStruct/SerdeNode), then rendered to a
    target text format through the pure-virtual SerdeBase interface.
  • A Json example (in tests) demonstrates extensibility; Xml/Toml can be added by
    overriding the wrapper/gap hooks.

Changes

  • Tree (seralize.{hpp,cpp}): SerdeStruct(ObjectId)/(Value) builds a SerdeNode tree (Object/Array/Map/basic) via ClassInfo::for_each_field + get_field, with recursive nesting. SerdeNode stores format-neutral raw leaf values and exposes get_key/get_val/get_type/get_children; SerdeStruct::root().
  • SerdeBase (serdebase.{hpp,cpp}): template method seralize(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).
  • Reflection registry: make_getter/make_setter/deduce_type now support Array/Map object members (previously fell through to Null).
  • Build: register seralize.cpp + serdebase.cpp in src/core/CMakeLists.txt.
  • Tests: test_serdebase.cpp defines a Json subclass and asserts exact output (incl. nested array/map); test_seralize.cpp covers object-to-tree output. The temporary SerdeStruct::to_string() was removed in favor of SerdeBase.

Verification

test_serdebase and test_seralize both 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 private core/reflect/seralize.hpp; promote the
    tree types to include/gkit/ once SerdeStruct leaves its temporary state.
  • Deserialization (deserialize) not implemented yet; SerdeStruct(const Value) remains
    declared but undefined.

CoraBlack added 11 commits July 31, 2026 21:18
- 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
@CoraBlack
CoraBlack merged commit 83aa6d4 into gkit-org:main Aug 3, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in libgkit-dev-record Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant