My use case is that I have an application producing protobuf messages. This application is getting notified with proto file content when there is a change in schema. And from that point my application has to ensure that each protobuf message meets the proto file schema. Any ideas on how to implement it?
1 Answers
There are a few different ways you could approach this:
You could the standard Protocol Buffers (https://developers.google.com/protocol-buffers/) (https://go.dev/blog/protobuf-apiv2) to compile your proto file. You could then use the module to validate your protobuf messages.
Alternatively, you could write a custom parser for your proto file. This would involve writing some code to validate the syntax of the proto file, and then writing code to validate the protobuf messages against the schema.
Finally, you could use a schema validation tool like Avro (http://avro.apache.org/). This would also involve compiling your proto file into a Python module, but would provide you with additional functionality for validating your protobuf messages.
I would probably try something with the standard library.

- 2,304
- 3
- 24
- 42
-
any idea on how to validate my proto file content is ok? – Idan Asulin Oct 12 '22 at 14:12
-
@JDong, could you point me in the direction for #1 module you're referring to, (I'm assuming validate package?) or point me in the direction on what to do for #2? I'm currently using the validate package to handle the validation of the data, and a custom package that allows me json tags: `string id = 1; // @gotags: validate:"required,uuid"` but I am wondering if this is the proper way, I feel like I should be validating something before it hits the server. – i73 Jun 20 '23 at 03:14