Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnullarrayfloat.go
More file actions
Latest commit
100 lines (85 loc) · 1.81 KB
/
Copy pathnullarrayfloat.go
File metadata and controls
100 lines (85 loc) · 1.81 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
98
99
100
package nulltype
import (
"database/sql/driver"
"strings"
"unsafe"
jsoniter "github.com/json-iterator/go"
)
/* SQL and JSon null.ArrayFloat */
typeArrayFloat[Tfloat32|float64] struct {
Array []T
Validbool
}
funcNewArrayFloat[Tfloat32|float64](i []T) ArrayFloat[T] {
n:=ArrayFloat[T]{}
n.Valid=true
n.Array=i
returnn
}
func (ni*ArrayFloat[T]) Encode(ptr unsafe.Pointer, stream*jsoniter.Stream) {
val:= (*ArrayFloat[T])(ptr)
ifval.Valid {
stream.WriteVal(val.Array)
} else {
stream.WriteVal(nil)
}
}
// IsEmpty detect whether primitive.ObjectID is empty.
func (ni*ArrayFloat[T]) IsEmpty(ptr unsafe.Pointer) bool {
val:= (*ArrayFloat[T])(ptr)
return!val.Valid
}
func (ni*ArrayFloat[T]) UnmarshalCSV(bstring) error {
vari []T
iferr:=json.Unmarshal([]byte(b), &i); err!=nil {
returnerr
}
ifstrings.Compare(b, "null") ==0 {
ni.Valid=false
returnnil
}
ni.Array=i
ni.Valid=true
returnnil
}
// MarshalCSV marshals CSV
func (niArrayFloat[T]) MarshalCSV() (string, error) {
ifni.Valid {
b, err:=json.Marshal(ni.Array)
returnstring(b), err
}
return"", nil
}
func (ni*ArrayFloat[T]) UnmarshalJSON(b []byte) error {
vari []T
iferr:=json.Unmarshal([]byte(b), &i); err!=nil {
returnerr
}
ifstrings.Compare(string(b), "null") ==0 {
ni.Valid=false
returnnil
}
ni.Array=i
ni.Valid=true
returnnil
}
func (niArrayFloat[T]) MarshalJSON() ([]byte, error) {
ifni.Valid {
returnjson.Marshal(ni.Array)
}
returnjson.Marshal(nil)
}
func (ni*ArrayFloat[T]) Scan(valueany) error {
ifvalue==nil {
ni.Array, ni.Valid=make([]T, 0), false
returnnil
}
ni.Valid=true
returnconvertAssignRows(&ni.Array, value)
}
func (niArrayFloat[T]) Value() (driver.Value, error) {
if!ni.Valid {
returnnil, nil
}
returnni.Array, nil
}