-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Check if property is part of proto schema #526
Comments
There is foo.verify(validMessage); // returns null if the message is considered valid, otherwise a string why it is not
The reason why this has its own method is performance. Let's say you already know for sure that the message is valid, because you double checked it, which is what I for example usually do, then calling verify implicitly would be unnecessary. Nonetheless, like encode/decode also verify is generated code and thus about as fast as it probably can be. |
Ok, it makes perfect sense from a performance point of view. However I found protobufjs v5 behavior was quite useful and very explicit on errors (eg. when trying to call a service method with wrong arguments for example) Not sure to understand how
|
I will probably go ahead and refactor the code generator anyway. Somewhat related: #521 The resulting implementation would then not just have code generation for encode, decode and verify but also for initialize and convert (to JSON). I'd then also update the verifier to perform type-checking as this is in fact quite useful and shouldn't be much of an issue as verify is optional anyway. |
Ok 👍 |
Actually, wrong thread, moved the post to the other one. |
This commit adds type checking to the verifier. It's quite strict. Let me know if you experience any issues. Note: This doesn't work with map fields, yet. |
Is there a way to check if a plain object is valid regarding to its protobuf message type ?
If I remember correctly, protobufjs v5 was doing so before encoding a message.
I didnt find a way to do it in protobufjs v6
Eg, given this proto :
The text was updated successfully, but these errors were encountered: