I use Google protocol buffers in a messaging application. Protos are often nested at several levels in depth, and we accepted Googleβs recommendations and made them all optional. Protos can describe many different types of overlapping messages, that is, a message of type == X must contain the element my_X, type == Y must contain my_Y. In addition, certain combinations of fields impose other restrictions on which fields should be present and what values ββthey should have. Changing the proto-structure is beyond what I can do.
Right now, this whole check is in the mess of if..else. If the cases do not match, this may be workable, but the verification cases may impose various restrictions on a particular field, so it can become quite ugly. Is there a better way? My goal is to make the code more convenient. I was looking a bit for functors / predicates, and it looks like this might simplify the problem, but it still seems like it will be a mess.
source share