Validate returns an error if the version list is not sorted or contains duplicate major versions.
()
| 113 | // Validate returns an error if the version list is not sorted or contains |
| 114 | // duplicate major versions. |
| 115 | func (vl RPCVersionList) Validate() error { |
| 116 | if len(vl.Versions) == 0 { |
| 117 | return xerrors.New("no versions") |
| 118 | } |
| 119 | for i := 0; i < len(vl.Versions); i++ { |
| 120 | if vl.Versions[i].Major == 0 { |
| 121 | return xerrors.Errorf("invalid version: %s", vl.Versions[i].String()) |
| 122 | } |
| 123 | if i > 0 && vl.Versions[i-1].Major == vl.Versions[i].Major { |
| 124 | return xerrors.Errorf("duplicate major version: %d", vl.Versions[i].Major) |
| 125 | } |
| 126 | if i > 0 && vl.Versions[i-1].Major > vl.Versions[i].Major { |
| 127 | return xerrors.Errorf("versions are not sorted") |
| 128 | } |
| 129 | } |
| 130 | return nil |
| 131 | } |
| 132 | |
| 133 | // IsCompatibleWith returns the lowest version that is compatible with both |
| 134 | // version lists. If the versions are not compatible, the second return value |
no test coverage detected