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.

On Fri, Oct 28, 2022 at 10:37 PM Idan Asulin <i...@memphis.dev> wrote:

> Didn't mention but I'm using the Go official library
>
> On Saturday, 29 October 2022 at 08:35:16 UTC+3 Idan Asulin wrote:
>
>> 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?
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/59f6cb9f-33ae-4fc1-ba07-93d3d8c90431n%40googlegroups.com
> <https://groups.google.com/d/msgid/protobuf/59f6cb9f-33ae-4fc1-ba07-93d3d8c90431n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CADqAXr58PCmZuzjYV4BaGKeacUPFEK-J%3D5ky1f7TrofBK8%2Bhhw%40mail.gmail.com.

Reply via email to