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 |
|
---|
5 | package protoimpl
|
---|
6 |
|
---|
7 | import (
|
---|
8 | "google.golang.org/protobuf/internal/version"
|
---|
9 | )
|
---|
10 |
|
---|
11 | const (
|
---|
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:
|
---|
29 | // - the runtime package is too old and needs to be updated OR
|
---|
30 | // - the generated code is too old and needs to be regenerated.
|
---|
31 | //
|
---|
32 | // The runtime package can be upgraded by running:
|
---|
33 | //
|
---|
34 | // go get google.golang.org/protobuf
|
---|
35 | //
|
---|
36 | // The generated code can be regenerated by running:
|
---|
37 | //
|
---|
38 | // protoc --go_out=${PROTOC_GEN_GO_ARGS} ${PROTO_FILES}
|
---|
39 | //
|
---|
40 | // Example usage by generated code:
|
---|
41 | //
|
---|
42 | // 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).
|
---|
52 | type EnforceVersion uint
|
---|
53 |
|
---|
54 | // This enforces the following invariant:
|
---|
55 | //
|
---|
56 | // MinVersion ≤ GenVersion ≤ MaxVersion
|
---|
57 | const (
|
---|
58 | _ = EnforceVersion(GenVersion - MinVersion)
|
---|
59 | _ = EnforceVersion(MaxVersion - GenVersion)
|
---|
60 | )
|
---|