-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
I'm writing a tool that produces a bunch of configuration files which are text-serialized protos. These configuration files are checked in into a repository. There may be multiple versions of this tool used as the same time (different developers may use slightly different binaries).
https://godoc.org/google.golang.org/protobuf/internal/detrand makes it produce confusing whitespace diffs when two or more developer work in this config files repo. I believe a use case of checking in text-serialized proto files is quite popular.
Additionally, when writing unit tests, I was very confused why changing a completely unrelated portion of the code makes tests suddenly fail. It looked like a compiler bug :) (it is never a compiler bug...) Consider documenting non-determinism in https://godoc.org/google.golang.org/protobuf/encoding/prototext
But ideally, something like this would be the best:
type MarshalOptions struct {
...
// Deterministic allows to disable randomizations added by the marshaller by
// default.
//
// Note that the output still can arbitrarily depend on the exact version of
// protobuf library. Setting this option to true only guarantees that
// identical messages serialized by the exact same version of protobuf
// library result in the exact same output.
Deterministic bool
}
That way clueless users would get randomization by default, and more inquisitive ones will discover the disclaimer and proceed on their own risk.