Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIv2: consider Message.IsValidValue #958

Closed
neild opened this issue Sep 27, 2019 · 3 comments
Closed

APIv2: consider Message.IsValidValue #958

neild opened this issue Sep 27, 2019 · 3 comments

Comments

@neild
Copy link
Contributor

@neild neild commented Sep 27, 2019

Should we have a way to test a Value for compatibility with a message field, along the lines of ExtensionType.IsValidValue?

This could either be a method on MessageType or Message.

@dsnet dsnet added the blocks-v2 label Sep 27, 2019
@dsnet
Copy link
Member

@dsnet dsnet commented Sep 27, 2019

Marking as blocks-v2 since this can't be changed after release.

Is this hypothetical, or did you have a real need for this?

I've seen the use for a semi-related validation function. Something like Message.IsValidFieldDescriptor, which takes in a FieldDescriptor and reports whether it is valid for that message or not.

@neild
Copy link
Contributor Author

@neild neild commented Sep 27, 2019

I was updating a bit of code (previously Go reflection, now protoreflect) that copies a list of named fields from one message to another message of a different type. There's no simple way to catch a field type mismatch; you can compare the descriptors, but that won't catch the (admittedly unusual) case where the descriptors are the same but the Go types aren't.

It's nothing you can't work around, but got me wondering whether there should be an easy way to do this for non-extension fields.

@dsnet
Copy link
Member

@dsnet dsnet commented Feb 10, 2020

Nice to have, but we both agreed that the use cases didn't seem all that compelling.

@dsnet dsnet closed this Feb 10, 2020
@neild neild removed the blocks-v2 label Feb 10, 2020
@golang golang locked and limited conversation to collaborators Sep 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.