forked from segmentio/stats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
reflect.go
103 lines (82 loc) · 2.46 KB
/
reflect.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
98
99
100
101
102
103
package stats
import (
"reflect"
"time"
"unsafe"
)
type structField struct {
typ reflect.Type
off uintptr
}
func (f structField) pointer(ptr unsafe.Pointer) unsafe.Pointer {
return unsafe.Pointer(uintptr(ptr) + f.off)
}
func (f structField) value(ptr unsafe.Pointer) reflect.Value {
return reflect.NewAt(f.typ, f.pointer(ptr))
}
func (f structField) bool(ptr unsafe.Pointer) bool {
return *(*bool)(f.pointer(ptr))
}
func (f structField) int(ptr unsafe.Pointer) int {
return *(*int)(f.pointer(ptr))
}
func (f structField) int8(ptr unsafe.Pointer) int8 {
return *(*int8)(f.pointer(ptr))
}
func (f structField) int16(ptr unsafe.Pointer) int16 {
return *(*int16)(f.pointer(ptr))
}
func (f structField) int32(ptr unsafe.Pointer) int32 {
return *(*int32)(f.pointer(ptr))
}
func (f structField) int64(ptr unsafe.Pointer) int64 {
return *(*int64)(f.pointer(ptr))
}
func (f structField) uint(ptr unsafe.Pointer) uint {
return *(*uint)(f.pointer(ptr))
}
func (f structField) uint8(ptr unsafe.Pointer) uint8 {
return *(*uint8)(f.pointer(ptr))
}
func (f structField) uint16(ptr unsafe.Pointer) uint16 {
return *(*uint16)(f.pointer(ptr))
}
func (f structField) uint32(ptr unsafe.Pointer) uint32 {
return *(*uint32)(f.pointer(ptr))
}
func (f structField) uint64(ptr unsafe.Pointer) uint64 {
return *(*uint64)(f.pointer(ptr))
}
func (f structField) uintptr(ptr unsafe.Pointer) uintptr {
return *(*uintptr)(f.pointer(ptr))
}
func (f structField) float32(ptr unsafe.Pointer) float32 {
return *(*float32)(f.pointer(ptr))
}
func (f structField) float64(ptr unsafe.Pointer) float64 {
return *(*float64)(f.pointer(ptr))
}
func (f structField) duration(ptr unsafe.Pointer) time.Duration {
return *(*time.Duration)(f.pointer(ptr))
}
func (f structField) string(ptr unsafe.Pointer) string {
return *(*string)(f.pointer(ptr))
}
var (
boolType = reflect.TypeOf(false)
intType = reflect.TypeOf(int(0))
int8Type = reflect.TypeOf(int8(0))
int16Type = reflect.TypeOf(int16(0))
int32Type = reflect.TypeOf(int32(0))
int64Type = reflect.TypeOf(int64(0))
uintType = reflect.TypeOf(uint(0))
uint8Type = reflect.TypeOf(uint8(0))
uint16Type = reflect.TypeOf(uint16(0))
uint32Type = reflect.TypeOf(uint32(0))
uint64Type = reflect.TypeOf(uint64(0))
uintptrType = reflect.TypeOf(uintptr(0))
float32Type = reflect.TypeOf(float32(0))
float64Type = reflect.TypeOf(float64(0))
durationType = reflect.TypeOf(time.Duration(0))
stringType = reflect.TypeOf("")
)