-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
condition_value_type.go
53 lines (41 loc) · 1.2 KB
/
condition_value_type.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
// Copyright (c) 2017 Andrey Gayvoronsky <plandem@gmail.com>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package primitives
import "encoding/xml"
//ConditionValueType is a direct mapping of XSD ST_CfvoType
type ConditionValueType byte
//ConditionType maps for marshal/unmarshal process
var (
ToConditionValueType map[string]ConditionValueType
FromConditionValueType map[ConditionValueType]string
)
func (t ConditionValueType) String() string {
return FromConditionValueType[t]
}
//MarshalXMLAttr marshal ConditionValueType
func (t *ConditionValueType) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
attr := xml.Attr{Name: name}
if v, ok := FromConditionValueType[*t]; ok {
attr.Value = v
} else {
attr = xml.Attr{}
}
return attr, nil
}
//UnmarshalXMLAttr unmarshal ConditionValueType
func (t *ConditionValueType) UnmarshalXMLAttr(attr xml.Attr) error {
if v, ok := ToConditionValueType[attr.Value]; ok {
*t = v
}
return nil
}
//IsAllowed check if type is in list of allowed types
func (t *ConditionValueType) IsAllowed(allowed ...ConditionValueType) bool {
for _, a := range allowed {
if *t == a {
return true
}
}
return false
}