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