-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypehint.go
More file actions
97 lines (82 loc) · 2.75 KB
/
Copy pathtypehint.go
File metadata and controls
97 lines (82 loc) · 2.75 KB
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 binxml
import (
"encoding/xml"
"fmt"
)
const (
HintBool = "bool"
HintBytes = "b"
HintChars = "ch"
HintConst = "c"
HintDateTime = "t"
HintDecimal = "dec"
HintDouble = "d"
HintFloat = "f"
HintInt = "i"
HintQName = "q"
HintUint = "u64"
HintUUID = "uid"
HintTimeSpan = "s"
HintUnicode = "uch"
HintList = "lst" // this needs to be handled differently (if at all)
HintSeparator = ":"
)
const (
HintXmlNamespace = "wcfp"
HintXmlAttrName = "hint"
HintXmlAttrValArrayPrefix = "array"
HintXmlAttrValueArrayStart = "arraystart"
HintXmlAttrValueArrayBool = HintXmlAttrValArrayPrefix + "B"
HintXmlAttrValueArrayInt16 = HintXmlAttrValArrayPrefix + "I16"
HintXmlAttrValueArrayInt32 = HintXmlAttrValArrayPrefix + "I32"
HintXmlAttrValueArrayInt64 = HintXmlAttrValArrayPrefix + "I64"
HintXmlAttrValueArrayFloat = HintXmlAttrValArrayPrefix + "F"
HintXmlAttrValueArrayDouble = HintXmlAttrValArrayPrefix + "D"
HintXmlAttrValueArrayDecimal = HintXmlAttrValArrayPrefix + "Dec"
HintXmlAttrValueArrayDateTime = HintXmlAttrValArrayPrefix + "T"
HintXmlAttrValueArrayTimeSpan = HintXmlAttrValArrayPrefix + "S"
HintXmlAttrValueArrayUUid = HintXmlAttrValArrayPrefix + "UUID"
)
var (
// maps only record types with end element since arrays must contain only these
arrayTypeMarkerMap = map[byte]string{
RTBoolTextWithEndElement: HintXmlAttrValueArrayBool,
RTInt16TextWithEndElement: HintXmlAttrValueArrayInt16,
RTInt32TextWithEndElement: HintXmlAttrValueArrayInt32,
RTInt64TextWithEndElement: HintXmlAttrValueArrayInt64,
RTFloatTextWithEndElement: HintXmlAttrValueArrayFloat,
RTDoubleTextWithEndElement: HintXmlAttrValueArrayDouble,
RTDecimalTextWithEndElement: HintXmlAttrValueArrayDecimal,
RTDateTimeTextWithEndElement: HintXmlAttrValueArrayDateTime,
RTTimeSpanTextWithEndElement: HintXmlAttrValueArrayTimeSpan,
RTUuidTextWithEndElement: HintXmlAttrValueArrayUUid,
}
arrayTypeMarkerReverseMap = reverseMap(arrayTypeMarkerMap)
)
func TypeHint(hint string, apply bool) string {
if apply {
return hint + HintSeparator
}
return ""
}
func createArrayMarker(recordType byte) (xml.Attr, error) {
typeStr, ok := arrayTypeMarkerMap[recordType]
if !ok {
return xml.Attr{}, fmt.Errorf("invalid array type %d", recordType)
}
attr := xml.Attr{
Name: xml.Name{
Space: HintXmlNamespace,
Local: HintXmlAttrName,
},
Value: typeStr,
}
return attr, nil
}
func arrayTypeFromHint(typeStr string) (byte, error) {
arrType, ok := arrayTypeMarkerReverseMap[typeStr]
if !ok {
return 0, fmt.Errorf("unknown array type hint: %s", typeStr)
}
return arrType, nil
}