blob: a105cb23e03312f005f02ce3fd70cbca9a05cb55 [file] [log] [blame]
khenaidoo5fc5cea2021-08-11 17:39:16 -04001// 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
5package protoimpl
6
7import (
8 "google.golang.org/protobuf/internal/version"
9)
10
11const (
12 // MaxVersion is the maximum supported version for generated .pb.go files.
13 // It is always the current version of the module.
14 MaxVersion = version.Minor
15
16 // GenVersion is the runtime version required by generated .pb.go files.
17 // This is incremented when generated code relies on new functionality
18 // in the runtime.
19 GenVersion = 20
20
21 // MinVersion is the minimum supported version for generated .pb.go files.
22 // This is incremented when the runtime drops support for old code.
23 MinVersion = 0
24)
25
26// EnforceVersion is used by code generated by protoc-gen-go
27// to statically enforce minimum and maximum versions of this package.
28// A compilation failure implies either that:
Joey Armstrongba3d9d12024-01-15 14:22:11 -050029// - the runtime package is too old and needs to be updated OR
30// - the generated code is too old and needs to be regenerated.
khenaidoo5fc5cea2021-08-11 17:39:16 -040031//
32// The runtime package can be upgraded by running:
Joey Armstrongba3d9d12024-01-15 14:22:11 -050033//
khenaidoo5fc5cea2021-08-11 17:39:16 -040034// go get google.golang.org/protobuf
35//
36// The generated code can be regenerated by running:
Joey Armstrongba3d9d12024-01-15 14:22:11 -050037//
khenaidoo5fc5cea2021-08-11 17:39:16 -040038// protoc --go_out=${PROTOC_GEN_GO_ARGS} ${PROTO_FILES}
39//
40// Example usage by generated code:
Joey Armstrongba3d9d12024-01-15 14:22:11 -050041//
khenaidoo5fc5cea2021-08-11 17:39:16 -040042// const (
43// // Verify that this generated code is sufficiently up-to-date.
44// _ = protoimpl.EnforceVersion(genVersion - protoimpl.MinVersion)
45// // Verify that runtime/protoimpl is sufficiently up-to-date.
46// _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - genVersion)
47// )
48//
49// The genVersion is the current minor version used to generated the code.
50// This compile-time check relies on negative integer overflow of a uint
51// being a compilation failure (guaranteed by the Go specification).
52type EnforceVersion uint
53
54// This enforces the following invariant:
Joey Armstrongba3d9d12024-01-15 14:22:11 -050055//
khenaidoo5fc5cea2021-08-11 17:39:16 -040056// MinVersion ≤ GenVersion ≤ MaxVersion
57const (
58 _ = EnforceVersion(GenVersion - MinVersion)
59 _ = EnforceVersion(MaxVersion - GenVersion)
60)