-
Notifications
You must be signed in to change notification settings - Fork 0
/
assign.go
65 lines (63 loc) · 1.31 KB
/
assign.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 decoder
import (
"github.com/koykov/inspector"
"github.com/koykov/vector"
)
// AssignVectorNode implements assign callback to convert vector.Node to destination with arbitrary type.
func AssignVectorNode(dst, src any, _ inspector.AccumulativeBuffer) (ok bool) {
switch src.(type) {
case *vector.Node:
n := src.(*vector.Node)
if n.Type() == vector.TypeNull {
return
}
ok = true
switch dst.(type) {
case *[]byte:
*dst.(*[]byte) = n.Bytes()
case *string:
*dst.(*string) = n.String()
case *bool:
*dst.(*bool) = n.Bool()
case *int:
i, _ := n.Int()
*dst.(*int) = int(i)
case *int8:
i, _ := n.Int()
*dst.(*int8) = int8(i)
case *int16:
i, _ := n.Int()
*dst.(*int16) = int16(i)
case *int32:
i, _ := n.Int()
*dst.(*int32) = int32(i)
case *int64:
i, _ := n.Int()
*dst.(*int64) = i
case *uint:
u, _ := n.Uint()
*dst.(*uint) = uint(u)
case *uint8:
u, _ := n.Uint()
*dst.(*uint8) = uint8(u)
case *uint16:
u, _ := n.Uint()
*dst.(*uint16) = uint16(u)
case *uint32:
u, _ := n.Uint()
*dst.(*uint32) = uint32(u)
case *uint64:
u, _ := n.Uint()
*dst.(*uint64) = u
case *float32:
f, _ := n.Float()
*dst.(*float32) = float32(f)
case *float64:
f, _ := n.Float()
*dst.(*float64) = f
default:
ok = false
}
}
return
}