2021-10-27 07:41:05 +00:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 11:20:03 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
|
2021-10-27 07:41:05 +00:00
|
|
|
)
|
|
|
|
|
2022-03-23 15:35:44 +00:00
|
|
|
// Version represents revision number in SemVer scheme.
|
2021-10-27 07:41:05 +00:00
|
|
|
//
|
2023-03-07 11:20:03 +00:00
|
|
|
// Version is mutually compatible with git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs.Version
|
2022-03-23 15:35:44 +00:00
|
|
|
// message. See ReadFromV2 / WriteToV2 methods.
|
2021-10-27 07:41:05 +00:00
|
|
|
//
|
2022-03-23 15:35:44 +00:00
|
|
|
// Instances can be created using built-in var declaration.
|
|
|
|
//
|
|
|
|
// Note that direct typecast is not safe and may result in loss of compatibility:
|
2022-08-24 14:17:40 +00:00
|
|
|
//
|
|
|
|
// _ = Version(refs.Version{}) // not recommended
|
2022-03-23 15:35:44 +00:00
|
|
|
type Version refs.Version
|
2021-10-27 07:41:05 +00:00
|
|
|
|
2022-07-06 07:39:38 +00:00
|
|
|
const sdkMjr, sdkMnr = 2, 13
|
2022-03-23 15:35:44 +00:00
|
|
|
|
|
|
|
// Current returns Version instance that initialized to the
|
2022-12-29 10:46:18 +00:00
|
|
|
// latest supported FrostFS API revision number in SDK.
|
2022-03-23 15:35:44 +00:00
|
|
|
func Current() (v Version) {
|
2021-10-27 07:41:05 +00:00
|
|
|
v.SetMajor(sdkMjr)
|
|
|
|
v.SetMinor(sdkMnr)
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Major returns major number of the revision.
|
|
|
|
func (v *Version) Major() uint32 {
|
|
|
|
return (*refs.Version)(v).GetMajor()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMajor sets major number of the revision.
|
|
|
|
func (v *Version) SetMajor(val uint32) {
|
|
|
|
(*refs.Version)(v).SetMajor(val)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Minor returns minor number of the revision.
|
|
|
|
func (v *Version) Minor() uint32 {
|
|
|
|
return (*refs.Version)(v).GetMinor()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMinor sets minor number of the revision.
|
|
|
|
func (v *Version) SetMinor(val uint32) {
|
|
|
|
(*refs.Version)(v).SetMinor(val)
|
|
|
|
}
|
|
|
|
|
2022-03-23 15:35:44 +00:00
|
|
|
// WriteToV2 writes Version to the refs.Version message.
|
|
|
|
// The message must not be nil.
|
2021-10-27 07:41:05 +00:00
|
|
|
//
|
2022-03-23 15:35:44 +00:00
|
|
|
// See also ReadFromV2.
|
|
|
|
func (v Version) WriteToV2(m *refs.Version) {
|
|
|
|
*m = (refs.Version)(v)
|
2021-10-27 07:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-07-07 10:51:05 +00:00
|
|
|
// ReadFromV2 reads Version from the refs.Version message. Checks if the message
|
2022-12-29 10:46:18 +00:00
|
|
|
// conforms to FrostFS API V2 protocol.
|
2022-03-23 15:35:44 +00:00
|
|
|
//
|
|
|
|
// See also WriteToV2.
|
2022-07-07 10:51:05 +00:00
|
|
|
func (v *Version) ReadFromV2(m refs.Version) error {
|
2022-03-23 15:35:44 +00:00
|
|
|
*v = Version(m)
|
2022-07-07 10:51:05 +00:00
|
|
|
return nil
|
2021-10-27 07:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 08:43:34 +00:00
|
|
|
// String implements fmt.Stringer.
|
|
|
|
//
|
|
|
|
// String is designed to be human-readable, and its format MAY differ between
|
|
|
|
// SDK versions.
|
2022-03-23 15:35:44 +00:00
|
|
|
func (v Version) String() string {
|
2022-04-12 08:43:34 +00:00
|
|
|
return EncodeToString(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeToString encodes version according to format from specification:
|
|
|
|
// semver formatted value without patch and with v prefix, e.g. 'v2.1'.
|
|
|
|
func EncodeToString(v Version) string {
|
2022-03-23 15:35:44 +00:00
|
|
|
return fmt.Sprintf("v%d.%d", v.Major(), v.Minor())
|
2021-10-27 07:41:05 +00:00
|
|
|
}
|
2022-03-28 08:15:52 +00:00
|
|
|
|
|
|
|
// Equal returns true if versions are identical.
|
|
|
|
func (v Version) Equal(v2 Version) bool {
|
|
|
|
return v.Major() == v2.Major() &&
|
|
|
|
v.Minor() == v2.Minor()
|
|
|
|
}
|