Dynamic message schema verification

36 visualizações
Ir para a primeira mensagem não lida

Idan Asulin

não lida,
29/10/2022, 01:35:1629/10/22
para Protocol Buffers
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).

1. Is it ok to rely on the unmarshal function in order to decide whether the message is ok?
2. I noticed that even in case I'm sending messages with totally different schemas the unmarshal succeed. the only way I found to cause the unmarshal to fail is by sending proto2 messages with missing required fields.
So is it by design that every message can be unmarshled using a totally different schema definition? 

Idan Asulin

não lida,
29/10/2022, 01:37:3029/10/22
para Protocol Buffers
Didn't mention but I'm using the Go official library

Adam Cozzette

não lida,
31/10/2022, 14:10:0931/10/22
para Idan Asulin,Protocol Buffers
What you're trying to do should work in the sense that it will determine whether the message is parsable as the type given in the descriptor. However, you are correct that a message of one type can very often be parsed successfully as a completely different type. This is indeed by design, since this level of flexibility is needed so that message definitions can evolve over time without breaking wire compatibility.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/59f6cb9f-33ae-4fc1-ba07-93d3d8c90431n%40googlegroups.com.
Responder a todos
Responder ao autor
Reencaminhar
0 mensagens novas