forked from ohler55/ojg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfint.go
100 lines (81 loc) · 2.82 KB
/
fint.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
// Copyright (c) 2021, Peter Ohler, All rights reserved.
package oj
import (
"reflect"
"strconv"
"unsafe"
)
var intAppendFuncs = [8]appendFunc{
appendInt,
appendIntAsString,
appendIntNotEmpty,
appendIntNotEmptyAsString,
iappendInt,
iappendIntAsString,
iappendIntNotEmpty,
iappendIntNotEmptyAsString,
}
func appendInt(fi *finfo, buf []byte, rv reflect.Value, addr uintptr, safe bool) ([]byte, interface{}, appendStatus) {
buf = append(buf, fi.jkey...)
buf = strconv.AppendInt(buf, int64(*(*int)(unsafe.Pointer(addr + fi.offset))), 10)
return buf, nil, aWrote
}
func appendIntAsString(fi *finfo, buf []byte, rv reflect.Value, addr uintptr, safe bool) ([]byte, interface{}, appendStatus) {
buf = append(buf, fi.jkey...)
buf = append(buf, '"')
buf = strconv.AppendInt(buf, int64(*(*int)(unsafe.Pointer(addr + fi.offset))), 10)
buf = append(buf, '"')
return buf, nil, aWrote
}
func appendIntNotEmpty(fi *finfo, buf []byte, rv reflect.Value, addr uintptr, safe bool) ([]byte, interface{}, appendStatus) {
v := *(*int)(unsafe.Pointer(addr + fi.offset))
if v == 0 {
return buf, nil, aSkip
}
buf = append(buf, fi.jkey...)
buf = strconv.AppendInt(buf, int64(v), 10)
return buf, nil, aWrote
}
func appendIntNotEmptyAsString(fi *finfo, buf []byte, rv reflect.Value, addr uintptr, safe bool) ([]byte, interface{}, appendStatus) {
v := *(*int)(unsafe.Pointer(addr + fi.offset))
if v == 0 {
return buf, nil, aSkip
}
buf = append(buf, fi.jkey...)
buf = append(buf, '"')
buf = strconv.AppendInt(buf, int64(v), 10)
buf = append(buf, '"')
return buf, nil, aWrote
}
func iappendInt(fi *finfo, buf []byte, rv reflect.Value, addr uintptr, safe bool) ([]byte, interface{}, appendStatus) {
buf = append(buf, fi.jkey...)
buf = strconv.AppendInt(buf, int64(rv.FieldByIndex(fi.index).Interface().(int)), 10)
return buf, nil, aWrote
}
func iappendIntAsString(fi *finfo, buf []byte, rv reflect.Value, addr uintptr, safe bool) ([]byte, interface{}, appendStatus) {
buf = append(buf, fi.jkey...)
buf = append(buf, '"')
buf = strconv.AppendInt(buf, int64(rv.FieldByIndex(fi.index).Interface().(int)), 10)
buf = append(buf, '"')
return buf, nil, aWrote
}
func iappendIntNotEmpty(fi *finfo, buf []byte, rv reflect.Value, addr uintptr, safe bool) ([]byte, interface{}, appendStatus) {
v := rv.FieldByIndex(fi.index).Interface().(int)
if v == 0 {
return buf, nil, aSkip
}
buf = append(buf, fi.jkey...)
buf = strconv.AppendInt(buf, int64(v), 10)
return buf, nil, aWrote
}
func iappendIntNotEmptyAsString(fi *finfo, buf []byte, rv reflect.Value, addr uintptr, safe bool) ([]byte, interface{}, appendStatus) {
v := rv.FieldByIndex(fi.index).Interface().(int)
if v == 0 {
return buf, nil, aSkip
}
buf = append(buf, fi.jkey...)
buf = append(buf, '"')
buf = strconv.AppendInt(buf, int64(v), 10)
buf = append(buf, '"')
return buf, nil, aWrote
}