version.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2019 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package protoimpl
  5. import (
  6. "google.golang.org/protobuf/internal/version"
  7. )
  8. const (
  9. // MaxVersion is the maximum supported version for generated .pb.go files.
  10. // It is always the current version of the module.
  11. MaxVersion = version.Minor
  12. // GenVersion is the runtime version required by generated .pb.go files.
  13. // This is incremented when generated code relies on new functionality
  14. // in the runtime.
  15. GenVersion = 20
  16. // MinVersion is the minimum supported version for generated .pb.go files.
  17. // This is incremented when the runtime drops support for old code.
  18. MinVersion = 0
  19. )
  20. // EnforceVersion is used by code generated by protoc-gen-go
  21. // to statically enforce minimum and maximum versions of this package.
  22. // A compilation failure implies either that:
  23. // * the runtime package is too old and needs to be updated OR
  24. // * the generated code is too old and needs to be regenerated.
  25. //
  26. // The runtime package can be upgraded by running:
  27. // go get google.golang.org/protobuf
  28. //
  29. // The generated code can be regenerated by running:
  30. // protoc --go_out=${PROTOC_GEN_GO_ARGS} ${PROTO_FILES}
  31. //
  32. // Example usage by generated code:
  33. // const (
  34. // // Verify that this generated code is sufficiently up-to-date.
  35. // _ = protoimpl.EnforceVersion(genVersion - protoimpl.MinVersion)
  36. // // Verify that runtime/protoimpl is sufficiently up-to-date.
  37. // _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - genVersion)
  38. // )
  39. //
  40. // The genVersion is the current minor version used to generated the code.
  41. // This compile-time check relies on negative integer overflow of a uint
  42. // being a compilation failure (guaranteed by the Go specification).
  43. type EnforceVersion uint
  44. // This enforces the following invariant:
  45. // MinVersion ≤ GenVersion ≤ MaxVersion
  46. const (
  47. _ = EnforceVersion(GenVersion - MinVersion)
  48. _ = EnforceVersion(MaxVersion - GenVersion)
  49. )