getml / reflect-cpp

A C++20 library for fast serialization, deserialization and validation using reflection. Supports JSON, BSON, CBOR, flexbuffers, msgpack, TOML, XML, YAML / msgpack.org[C++20]
https://getml.github.io/reflect-cpp/
MIT License
821 stars 66 forks source link

Q: How to Get Public Method List #51

Open lixin-wei opened 6 months ago

lixin-wei commented 6 months ago

Hi everyone, I'm working with classes like the following:

class Person {
public:
  int age() const;
private:
  int age_;
}

in which all fields are private but can be accessed by getter. This type of class is very common, e.g. Protobuf messages.

Is there any way to get the public method list from a class, so that I can access the fields in such classes?

Could any one help me? Thanks in advance!

liuzicheng1987 commented 6 months ago

At the moment something like this is not supported.

If you want to serialize or deserialize classes like this, you use one of the following solutions:

https://github.com/getml/reflect-cpp/blob/main/docs/custom_classes.md

https://github.com/getml/reflect-cpp/blob/main/docs/custom_parser.md

But I will think about how something like this could be done.