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

GeneratedMessageCompanion#parseFrom always successful even for incompatible types #66

Closed
mushtaq opened this issue Dec 22, 2015 · 1 comment

Comments

@mushtaq
Copy link

mushtaq commented Dec 22, 2015

println(B.parseFrom(A("hello", 100).toByteArray)) // B(0, "")
println(A.parseFrom(B(100, "hello").toByteArray)) // A("", 0)

Is this intended? Then why do we have a "validate" method? Is there a sbt setting to change these defaults and make it throw exception?

@thesamet
Copy link
Contributor

It depends on the definitions of A and B, but generally there is no way for the parser to know that it is getting bytes that are meant for a different message types. In some cases, it can detect that a message does not make sense and then it would throw an exception. The validate function is returning a Try that fails when those cases happen.

This behavior is a feature of the protobuf wire format that allows you to evolve your message schema.
https://developers.google.com/protocol-buffers/docs/proto#updating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants