-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.go
62 lines (49 loc) · 1.28 KB
/
objects.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
// 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"
//ObjectsType is a type to encode XSD ST_Objects
type ObjectsType byte
//List of all possible values for ObjectsType
const (
_ ObjectsType = iota
ObjectsTypeAll
ObjectsTypePlaceholders
ObjectsTypeNone
)
var (
toObjectsType map[string]ObjectsType
fromObjectsType map[ObjectsType]string
)
func init() {
fromObjectsType = map[ObjectsType]string{
ObjectsTypeAll: "all",
ObjectsTypePlaceholders: "placeholders",
ObjectsTypeNone: "none",
}
toObjectsType = make(map[string]ObjectsType, len(fromObjectsType))
for k, v := range fromObjectsType {
toObjectsType[v] = k
}
}
func (e ObjectsType) String() string {
return fromObjectsType[e]
}
//MarshalXMLAttr marshal ObjectsType
func (e *ObjectsType) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
attr := xml.Attr{Name: name}
if v, ok := fromObjectsType[*e]; ok {
attr.Value = v
} else {
attr = xml.Attr{}
}
return attr, nil
}
//UnmarshalXMLAttr unmarshal ObjectsType
func (e *ObjectsType) UnmarshalXMLAttr(attr xml.Attr) error {
if v, ok := toObjectsType[attr.Value]; ok {
*e = v
}
return nil
}