I'm looking for a string representation of arbitrary fields inside protocol buffer messages. Is there any library that implements this? I've looked at using field masks, however they don't have a strong support for repeated fields.
Asked
Active
Viewed 1,405 times
1
-
I don't understand the question. Can you add an example? – Stefan Haustein Sep 26 '18 at 20:56
-
Sure. I want to be able to annotate any field in a message with some metadata. I have another message defined for holding the annotation metadata and I want a way to identify which field this annotation applies to. So I'm looking for something like xpath for protobufs. – Michael Theodorides Sep 26 '18 at 22:20
-
I'd still recommend to add an example (and your additional problem description) to the question. It sounds like protocol buffer descriptors are what you need, but I am still not sure if I understand the problem correctly, and I suspect the same might hold for others, given that there is no answer yet. O:) – Stefan Haustein Sep 27 '18 at 07:58
-
Sure, let me share my problem description. I'm working with config data that is stored inside protocol buffers. I would like to add a feature that enables adding expiration dates to any fields. My plan would be to add a list of expiration messages to the proto that would contain an expiration date and a reference to which field is expiring. I would have a job that updates fields on expiration to their default values. Hopefully this description makes the problem more clear. Thanks! :) – Michael Theodorides Sep 28 '18 at 19:10
1 Answers
1
Protocol buffer message and field descriptors provide field access by name. This allows you to find a particular field using a path and to erase it, if that's what you are asking for (if not, I'd recommend to expand the question to include an example for what you'd like to do).
One corresponding Java method is getDescriptorForType (the return type is a message descriptor, where you'll find field descriptors).
There is a similar descriptor API for C++ (in Java, you could theoretically also use reflection).
This API is not available in light mode.

Stefan Haustein
- 18,427
- 3
- 36
- 51
-
Thanks for the answer! This is seems like it will do what I need. If I understand the API correctly, I will have to use recursion for nested fields and define my own syntax for a field path. Is this some standard syntax for field paths? – Michael Theodorides Oct 08 '18 at 22:10
-