bufbuild / protovalidate

Protocol Buffer Validation - Go, Java, Python, and C++ Beta Releases!
https://buf.build/bufbuild/protovalidate
Apache License 2.0
908 stars 37 forks source link

Some general questions #224

Closed dpservis closed 3 months ago

dpservis commented 4 months ago

Hi,

I am trying to figure out the following:

  1. Do I need protovalidate and protovalidate-cc when working with C++?
  2. How do I build on Windows?
  3. Does protovalidate generate validation code which needs extra runtime? If yes, why not generate validation code within the serialization classes?
rodaine commented 3 months ago

Hi, @dpservis!

Do I need protovalidate and protovalidate-cc when working with C++?

Your protos will have a dependency on those in protovalidate, and you will use the protovalidate-cc library to perform the validation on your messages.

How do I build on Windows?

Nothing in the protovalidate ecosystem is OS-specific. The same tooling you use to work with a C++ codebase on Windows is still applicable. I'd refer to the usage documentation in the protovalidate-cc repo for examples. If you encounter anything not working, or if there's anything that we can clarify in our documentation, please feel free to open an issue on the appropriate repository.

Does protovalidate generate validation code which needs extra runtime? If yes, why not generate validation code within the serialization classes?

Protovalidate does not perform any code generation; all validators are built at runtime and cached for that message type. Our blog post on the kickoff of protovalidate as a replacement for protoc-gen-validate, goes into details why code generation is not worth it in this space.

If the concern is performance, we have benchmark numbers for the Go implementation showing sub-100ns execution of validation rules against messages with an (amortized) zero allocations after the first time a message type is encountered.