Exclusion of `XXX` fields from unmarshalled objects when using protocmp and protoreflect

100 views
Skip to first unread message

Timothy Fall

unread,
Mar 2, 2020, 7:58:45 PM3/2/20
to golang-nuts
Hi Guys!
I've been working on a transient problem in the github.com/kubernetes/client-go library that keeps us from using an updated version of github.com/googleapis/gnostic. The tl;dr on the problem (which serves as background for my question) is that the tests make heavy use of `reflect.DeepEqual` and therefore encounter problems when `XXX_` fields are inserted into messages, a known issue. I discovered `cmp`, `protocmp`, `protoreflect` and dived pretty deep into the works on that, but haven't figured out how to accomplish the simple task I want. It seems like something others would encounter as well, so I'm asking here.

My goal is to strip messages of the `XXX_` fields (preferably after the `Unmarshalling` step) in order to do comparisons without those fields throwing off `cmp`. I've seen some discussion around using UnmarshallOptions to do some transformations, but this would require all component libraries to be using APIv2 (and implement `protoreflect.MessageReflect`), and not the backwards compatibility of APIv1. What is the idiomatic way to accomplish this?



This might serve as a good example to document in the `protocmp` package? I imagine a lot of people are going to be running into this issue or something like it.

-Tim
Reply all
Reply to author
Forward
0 new messages