-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
65 lines (61 loc) · 1.22 KB
/
types.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
package nbt
import "reflect"
const (
tagEnd = 0
tagByte = 1
tagShort = 2
tagInt = 3
tagLong = 4
tagFloat = 5
tagDouble = 6
tagByteArray = 7
tagString = 8
tagList = 9
tagCompound = 10
)
// C is a wrapper for map[string]interface{}
type C map[string]interface{}
func getType(v interface{}) (byte, bool) {
switch v := v.(type) {
case int:
switch {
case v < 127 && v > -128:
return tagByte, true
case v < 32767 && v > -32768:
return tagShort, true
case v < 2147483647 && v > -2147483648:
return tagInt, true
case v < 9223372036854775807 && v > -9223372036854775807:
return tagLong, true
default:
return tagEnd, false
}
case int8:
return tagByte, false
case int16:
return tagShort, false
case int32:
return tagInt, false
case int64:
return tagLong, false
case float32:
return tagFloat, false
case float64:
return tagDouble, false
case []byte:
return tagByteArray, false
case string:
return tagString, false
case C:
return tagCompound, false
case map[string]interface{}:
return tagCompound, false
default:
val := reflect.TypeOf(v)
if val.Kind() == reflect.Slice {
return tagList, false
} else {
return tagEnd, false
}
}
}