I'm trying to implement data contract logic. I've 2 services switching messages with each other. Service A send messages in some format + the file descriptor proto of the .proto file used to generate it. Service B gets them both, the message and the file descriptor proto and has to ensure the message doesn't break the schema defenition. What I've did until now is to create a dynamic message instance using the descriptor proto and tried to unmarshal the message into the dynamic message instance, and in case no error occurred during the unmarshal process it counts as a success (message doesn't break the schema).
message MyMessage {
uint64 id = 1;
string name = 2;
string surname = 3;
}
If your server receives message that contains just id
and name
and your server is trying to unmarshal this message, id
and name
fields would be unmarshaled while surname
field in your structure would be empty.
This approach appliable for JSONs too.