-
Notifications
You must be signed in to change notification settings - Fork 7
/
accessor.go
382 lines (331 loc) · 10.1 KB
/
accessor.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
package xunsafe
import (
"github.com/viant/xreflect"
"time"
"unsafe"
)
// Interface cast field pointer to value
func (f *Field) Interface(structPtr unsafe.Pointer) interface{} {
ptr := f.Pointer(structPtr)
if f.ptrKind == ptrKindEmptyInterface {
return asInterface(ptr, f.rtype, true)
}
if f.ptrKind == ptrKindMethodInterface {
return *(*interface {
M()
})(ptr)
}
return *(*interface{})(ptr)
}
// Int cast field pointer to int
func (f *Field) Int(structPtr unsafe.Pointer) int {
f.MustBeAssignable(xreflect.IntType)
return AsInt(f.Pointer(structPtr))
}
// IntPtr cast field pointer to *int
func (f *Field) IntPtr(structPtr unsafe.Pointer) *int {
f.MustBeAssignable(xreflect.IntPtrType)
result := AsIntAddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Error cast field pointer to error
func (f *Field) Error(structPtr unsafe.Pointer) error {
f.MustBeAssignable(xreflect.ErrorType)
return AsError(f.Pointer(structPtr))
}
// ErrorPtr cast field pointer to *error
func (f *Field) ErrorPtr(structPtr unsafe.Pointer) *error {
f.MustBeAssignable(xreflect.ErrorPtrType)
result := AsErrorAddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// IntAddr cast field pointer to **int
func (f *Field) IntAddr(structPtr unsafe.Pointer) *int {
f.MustBeAssignable(xreflect.IntType)
return AsIntPtr(f.Pointer(structPtr))
}
// Int64 cast field pointer to int64
func (f *Field) Int64(structPtr unsafe.Pointer) int64 {
f.MustBeAssignable(xreflect.Int64Type)
return AsInt64(f.Pointer(structPtr))
}
// Int64Ptr cast field pointer to *int
func (f *Field) Int64Ptr(structPtr unsafe.Pointer) *int64 {
f.MustBeAssignable(xreflect.Int64PtrType)
result := AsInt64AddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Int64Addr cast field pointer to *int64
func (f *Field) Int64Addr(structPtr unsafe.Pointer) *int64 {
f.MustBeAssignable(xreflect.Int64Type)
return AsInt64Ptr(f.Pointer(structPtr))
}
// Int32 cast field pointer to int32
func (f *Field) Int32(structPtr unsafe.Pointer) int32 {
f.MustBeAssignable(xreflect.Int32Type)
return AsInt32(f.Pointer(structPtr))
}
// Int32Ptr cast field pointer to *int32
func (f *Field) Int32Ptr(structPtr unsafe.Pointer) *int32 {
f.MustBeAssignable(xreflect.Int32PtrType)
result := AsInt32AddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Int32Addr cast field pointer to *int32
func (f *Field) Int32Addr(structPtr unsafe.Pointer) *int32 {
f.MustBeAssignable(xreflect.Int32Type)
return AsInt32Ptr(f.Pointer(structPtr))
}
// Int16 cast field pointer to int16
func (f *Field) Int16(structPtr unsafe.Pointer) int16 {
f.MustBeAssignable(xreflect.Int16Type)
return AsInt16(f.Pointer(structPtr))
}
// Int16Ptr cast field pointer to *int16
func (f *Field) Int16Ptr(structPtr unsafe.Pointer) *int16 {
f.MustBeAssignable(xreflect.Int16PtrType)
result := AsInt16AddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Int16Addr returns *int16
func (f *Field) Int16Addr(structPtr unsafe.Pointer) *int16 {
f.MustBeAssignable(xreflect.Int16Type)
return AsInt16Ptr(f.Pointer(structPtr))
}
// Int8 cast field pointer to int8
func (f *Field) Int8(structPtr unsafe.Pointer) int8 {
f.MustBeAssignable(xreflect.Int8Type)
return AsInt8(f.Pointer(structPtr))
}
// Int8Ptr cast field pointer to *int8
func (f *Field) Int8Ptr(structPtr unsafe.Pointer) *int8 {
f.MustBeAssignable(xreflect.Int8PtrType)
result := AsInt8AddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Int8Addr cast field pointer to *int8
func (f *Field) Int8Addr(structPtr unsafe.Pointer) *int8 {
f.MustBeAssignable(xreflect.Int8Type)
return AsInt8Ptr(f.Pointer(structPtr))
}
// UintAddr cast field pointer to **uint
func (f *Field) UintAddr(structPtr unsafe.Pointer) *uint {
f.MustBeAssignable(xreflect.UintType)
return AsUintPtr(f.Pointer(structPtr))
}
// Uint cast field pointer to uint
func (f *Field) Uint(structPtr unsafe.Pointer) uint {
f.MustBeAssignable(xreflect.UintType)
return AsUint(f.Pointer(structPtr))
}
// UintPtr cast field pointer to *uint
func (f *Field) UintPtr(structPtr unsafe.Pointer) *uint {
f.MustBeAssignable(xreflect.UintPtrType)
result := AsUintAddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Uint64 cast field pointer to uint64
func (f *Field) Uint64(structPtr unsafe.Pointer) uint64 {
f.MustBeAssignable(xreflect.Uint64Type)
return AsUint64(f.Pointer(structPtr))
}
// Uint64Ptr cast field pointer to *uint64
func (f *Field) Uint64Ptr(structPtr unsafe.Pointer) *uint64 {
f.MustBeAssignable(xreflect.Uint64PtrType)
result := AsUint64AddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Uint64Addr cast field pointer to *uint64
func (f *Field) Uint64Addr(structPtr unsafe.Pointer) *uint64 {
f.MustBeAssignable(xreflect.Uint64Type)
return AsUint64Ptr(f.Pointer(structPtr))
}
// Uint32 cast field pointer to uint32
func (f *Field) Uint32(structPtr unsafe.Pointer) uint32 {
f.MustBeAssignable(xreflect.Uint32Type)
return AsUint32(f.Pointer(structPtr))
}
// Uint32Ptr cast field pointer to *uint32
func (f *Field) Uint32Ptr(structPtr unsafe.Pointer) *uint32 {
f.MustBeAssignable(xreflect.Uint32PtrType)
result := AsUint32AddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Uint32Addr cast field pointer to *uint32
func (f *Field) Uint32Addr(structPtr unsafe.Pointer) *uint32 {
f.MustBeAssignable(xreflect.Uint32Type)
return AsUint32Ptr(f.Pointer(structPtr))
}
// Uint16 cast field pointer to uint16
func (f *Field) Uint16(structPtr unsafe.Pointer) uint16 {
f.MustBeAssignable(xreflect.Uint16Type)
return AsUint16(f.Pointer(structPtr))
}
// Uint16Ptr cast field pointer to *uint16
func (f *Field) Uint16Ptr(structPtr unsafe.Pointer) *uint16 {
f.MustBeAssignable(xreflect.Uint16PtrType)
result := AsUint16AddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Uint16Addr cast field pointer to *uint16
func (f *Field) Uint16Addr(structPtr unsafe.Pointer) *uint16 {
f.MustBeAssignable(xreflect.Uint16Type)
return AsUint16Ptr(f.Pointer(structPtr))
}
// Uint8 cast field pointer to uint8
func (f *Field) Uint8(structPtr unsafe.Pointer) uint8 {
f.MustBeAssignable(xreflect.Uint8Type)
return AsUint8(f.Pointer(structPtr))
}
// Uint8Ptr cast field pointer to *uint8
func (f *Field) Uint8Ptr(structPtr unsafe.Pointer) *uint8 {
f.MustBeAssignable(xreflect.Uint8PtrType)
result := AsUint8AddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Uint8Addr cast field pointer to *uint8
func (f *Field) Uint8Addr(structPtr unsafe.Pointer) *uint8 {
f.MustBeAssignable(xreflect.Uint8Type)
return AsUint8Ptr(f.Pointer(structPtr))
}
// Bool cast field pointer to bool
func (f *Field) Bool(structPtr unsafe.Pointer) bool {
f.MustBeAssignable(xreflect.BoolType)
return AsBool(f.Pointer(structPtr))
}
// BoolPtr cast field pointer to *bool
func (f *Field) BoolPtr(structPtr unsafe.Pointer) *bool {
f.MustBeAssignable(xreflect.BoolPtrType)
result := AsBoolAddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// BoolAddr cast field pointer to **bool
func (f *Field) BoolAddr(structPtr unsafe.Pointer) *bool {
f.MustBeAssignable(xreflect.BoolType)
return AsBoolPtr(f.Pointer(structPtr))
}
// Float64 cast field pointer to float64
func (f *Field) Float64(structPtr unsafe.Pointer) float64 {
f.MustBeAssignable(xreflect.Float64Type)
return AsFloat64(f.Pointer(structPtr))
}
// Float64Ptr cast field pointer to *float64
func (f *Field) Float64Ptr(structPtr unsafe.Pointer) *float64 {
f.MustBeAssignable(xreflect.Float64PtrType)
result := AsFloat64AddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Float64Addr cast field pointer to *float64
func (f *Field) Float64Addr(structPtr unsafe.Pointer) *float64 {
f.MustBeAssignable(xreflect.Float64Type)
return AsFloat64Ptr(f.Pointer(structPtr))
}
// Float32 cast field pointer to float32
func (f *Field) Float32(structPtr unsafe.Pointer) float32 {
f.MustBeAssignable(xreflect.Float32Type)
return AsFloat32(f.Pointer(structPtr))
}
// Float32Ptr cast field pointer to *float32
func (f *Field) Float32Ptr(structPtr unsafe.Pointer) *float32 {
f.MustBeAssignable(xreflect.Float32PtrType)
result := AsFloat32AddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Float32Addr cast field pointer to *float32
func (f *Field) Float32Addr(structPtr unsafe.Pointer) *float32 {
f.MustBeAssignable(xreflect.Float32Type)
return AsFloat32Ptr(f.Pointer(structPtr))
}
// String cast field pointer to string
func (f *Field) String(structPtr unsafe.Pointer) string {
f.MustBeAssignable(xreflect.StringType)
return AsString(f.Pointer(structPtr))
}
// StringPtr cast field pointer to *string
func (f *Field) StringPtr(structPtr unsafe.Pointer) *string {
f.MustBeAssignable(xreflect.StringPtrType)
result := AsStringAddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// StringAddr field pointer to *string
func (f *Field) StringAddr(structPtr unsafe.Pointer) *string {
f.MustBeAssignable(xreflect.StringType)
return AsStringPtr(f.Pointer(structPtr))
}
// Bytes cast field pointer to []byte
func (f *Field) Bytes(structPtr unsafe.Pointer) []byte {
f.MustBeAssignable(xreflect.BytesType)
return AsUint8s(f.Pointer(structPtr))
}
// BytesPtr cast field pointer to *[]byte
func (f *Field) BytesPtr(structPtr unsafe.Pointer) *[]byte {
f.MustBeAssignable(xreflect.BytesPtrType)
result := AsBytesAddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// TimePtr cast field pointer to *time.Time
func (f *Field) TimePtr(structPtr unsafe.Pointer) *time.Time {
f.MustBeAssignable(xreflect.TimePtrType)
result := AsTimeAddrPtr(f.Pointer(structPtr))
if result == nil {
return nil
}
return *result
}
// Time cast field pointer to time.Time
func (f *Field) Time(structPtr unsafe.Pointer) time.Time {
f.MustBeAssignable(xreflect.TimeType)
return AsTime(f.Pointer(structPtr))
}
// Value returns field value
func (f *Field) Value(structPtr unsafe.Pointer) interface{} {
return f.Interface(structPtr)
}