Open thomasvl opened 6 years ago
Just stumbled upon this and I think it would be a great addition to swift-protobuf
. Currently facing an issue where elements of a collection can be returned in different orders while all the fields have the exact same values.
Any updates on this enhancement? Is that something we can hope in a near future?
No plans in the near future, and since there isn't a good way to do something like this generically in Swift at the moment.
We need support for Equatable/Hashable, so we have to bake in a definition, but looking at google/protobuf's language support C++ (and maybe Java) provide some interesting api to allow less strict handing around comparisons. Once the library and/or Swift it self has more support for reflection, it might make sense to provide something inspired by google/protof's src/google/protobuf/util/field_comparator.h and src/google/protobuf/util/message_differencer.h.
In addition to being able to tweak handing of float/double comparisons, default vs. explicit values, it could provide a way to control a subset of fields to compare. This last part would be a way to handle something like timestamps for last modification where that value doesn't really matter, just the values of the fields themselves; or for performance improvements, where a message might have a record/revision id, and comparing that is all that is needed to see if things are equal instead of an exhaustive comparison of fields.
Anyway, this is to look at adding apis like the upstream field_comparator and message_differencer, but expose them in a Swifty way for folks that needs customizable comparison of messages.