Unfortunately we don't have tools to access field counts at compile time. In order to do this we would have to increase the size of our generated files which is too big of a tradeoff for us to make.
On Friday, May 6, 2022 at 11:27:35 PM UTC-7 [email protected] wrote: > I'm working with Protobuf3 in my C++14 project. > > Let's say that I have such a message in some proto file: > > message User { > uint32 user_id = 1; > string user_name = 2; > map<string, string> others = 10; > }; > > Now, I'm trying to use the reflection mechanism in some functions to > process this message. > > I need to get the field counts of the message User, which should be 3. > > The doc > <https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.descriptor#Descriptor.field.details> > told > me that there was a function *field_count*(), which can give me the 3. > > However, it seems that this is a common runtime function. I could work > with it but I want to make come compile warning/error with static_assert. > So I need this 3 at compile time. > > Is it possible to get the field counts of a message at compile time? > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/bc49b835-c1bd-4108-8e5e-8a8698af57ecn%40googlegroups.com.
