msoucy / dproto

D Protocol Buffer mixins to create structures at compile time
Boost Software License 1.0
37 stars 16 forks source link

Can you expand to automatically read fields #112

Closed heketang closed 7 years ago

heketang commented 7 years ago

example: message ms; auto names = ms.arr_names; foreach(name;names) { auto value =ms.name;
}

heketang commented 7 years ago

thinks ,i have do the work.

timotheecour commented 7 years ago

standard protobufs have a reflection API (https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message) but thanks to dproto using compile time generation and CTFE, can't we use D's builtin functionality for this?

eg: foreach(memberName; __traits(allMembers, YourClass)) {...}

would that work?

msoucy commented 7 years ago

Indeed, using D's builtin compile time reflection is the preferable way to do this, in order to stay as idiomatic to D as possible.

heketang commented 7 years ago

@msoucy @timotheecour , Thanks, the reflection of dlang is so strong.