-
Notifications
You must be signed in to change notification settings - Fork 3
/
versionscheme.go
97 lines (83 loc) · 2.96 KB
/
versionscheme.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package swid
import (
"encoding/xml"
)
// VersionScheme models the version-scheme type.
type VersionScheme struct {
val interface{}
}
/*
$version-scheme /= multipartnumeric
$version-scheme /= multipartnumeric-suffix
$version-scheme /= alphanumeric
$version-scheme /= decimal
$version-scheme /= semver
$version-scheme /= uint / text
multipartnumeric = 1
multipartnumeric-suffix = 2
alphanumeric = 3
decimal = 4
semver = 16384
*/
// VersionScheme constants
const (
VersionSchemeMultipartNumeric = uint64(iota + 1)
VersionSchemeMultipartNumericSuffix
VersionSchemeAlphaNumeric
VersionSchemeDecimal
VersionSchemeSemVer = 16384
VersionSchemeUnknown = ^uint64(0)
)
var (
versionSchemeToString = map[uint64]string{
VersionSchemeMultipartNumeric: "multipartnumeric",
VersionSchemeMultipartNumericSuffix: "multipartnumeric+suffix",
VersionSchemeAlphaNumeric: "alphanumeric",
VersionSchemeDecimal: "decimal",
VersionSchemeSemVer: "semver",
}
stringToVersionScheme = map[string]uint64{
"multipartnumeric": VersionSchemeMultipartNumeric,
"multipartnumeric+suffix": VersionSchemeMultipartNumericSuffix,
"alphanumeric": VersionSchemeAlphaNumeric,
"decimal": VersionSchemeDecimal,
"semver": VersionSchemeSemVer,
}
)
// String returns the value of the VersionScheme receiver as a string
func (vs VersionScheme) String() string {
return codeStringer(vs.val, versionSchemeToString, "version-scheme")
}
// Check returns nil if the VersionScheme receiver is of type string or code-point
// (i.e., uint)
func (vs VersionScheme) Check() error {
return isStringOrCode(vs.val, "version-scheme")
}
// MarshalCBOR encodes the VersionScheme receiver as code-point if possible,
// otherwise as string
func (vs VersionScheme) MarshalCBOR() ([]byte, error) {
return codeToCBOR(vs.val, stringToVersionScheme)
}
// UnmarshalCBOR decodes the supplied data into a VersionScheme code-point if
// possible, otherwise as string
func (vs *VersionScheme) UnmarshalCBOR(data []byte) error {
return cborToCode(data, stringToVersionScheme, &vs.val)
}
// MarshalJSON encodes the VersionScheme receiver as string
func (vs VersionScheme) MarshalJSON() ([]byte, error) {
return codeToJSON(vs.val, versionSchemeToString)
}
// UnmarshalJSON decodes the supplied data into an VersionScheme code-point if
// possible, otherwise as string
func (vs *VersionScheme) UnmarshalJSON(data []byte) error {
return jsonToCode(data, stringToVersionScheme, &vs.val)
}
// MarshalXMLAttr encodes the VersionScheme receiver as XML attribute
func (vs VersionScheme) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
return codeToXMLAttr(name, vs.val, versionSchemeToString)
}
// UnmarshalXMLAttr decodes the supplied XML attribute into a VersionScheme
// code-point if possible, otherwise as string
func (vs *VersionScheme) UnmarshalXMLAttr(attr xml.Attr) error {
return xmlAttrToCode(attr, stringToVersionScheme, &vs.val)
}