You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

61 lines
2.0 KiB

  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. //
  28. // go get google.golang.org/protobuf
  29. //
  30. // The generated code can be regenerated by running:
  31. //
  32. // protoc --go_out=${PROTOC_GEN_GO_ARGS} ${PROTO_FILES}
  33. //
  34. // Example usage by generated code:
  35. //
  36. // const (
  37. // // Verify that this generated code is sufficiently up-to-date.
  38. // _ = protoimpl.EnforceVersion(genVersion - protoimpl.MinVersion)
  39. // // Verify that runtime/protoimpl is sufficiently up-to-date.
  40. // _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - genVersion)
  41. // )
  42. //
  43. // The genVersion is the current minor version used to generated the code.
  44. // This compile-time check relies on negative integer overflow of a uint
  45. // being a compilation failure (guaranteed by the Go specification).
  46. type EnforceVersion uint
  47. // This enforces the following invariant:
  48. //
  49. // MinVersion ≤ GenVersion ≤ MaxVersion
  50. const (
  51. _ = EnforceVersion(GenVersion - MinVersion)
  52. _ = EnforceVersion(MaxVersion - GenVersion)
  53. )