Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime: Add oneof lookup for fields
This modifies fieldByProtoName to do two things: 1. It may now return an error. It only does this for the oneof case right now, as the not-found case only causes the field to be skipped. 2. It will first look for the field name in the message's OneofTypes map. If the field matches a OneOf type, it will check first that the field is nil -- if it isn't, the field is already set and it returns an error. If nil, it allocates a new oneof type for the field and returns the first field of the oneof type. The reason for rejecting multiple oneof fields is that the runtime iterates over url.Values and gets pseudo-random key order, meaning that one field is selected out of several. We could address this by sorting the url.Values and picking the last seen, in which case the code is far simpler but involves allocating and sorting an array of field names before walking them (only to get predictable field selection). This change amends the error result tested for in TestPopulateParameters to include the name of oneof_value. Related to issue grpc-ecosystem#82. Change-Id: I7a5ecc9ce397bd71156cd4ac8690bae782ecc55e
- Loading branch information