forked from andreaTP/debezium-smt-go-pdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebezium.go
154 lines (121 loc) · 3.58 KB
/
debezium.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
package debezium
import (
"unsafe"
"github.com/debezium/debezium-smt-go-pdk/internal"
)
// access a nested field in the record data structure provided by Debezium
func Get(proxyPtr uint32, fieldName string) uint32 {
var fieldNameLen = len(fieldName) + 1
var fieldNamePtr = internal.Malloc(uintptr(fieldNameLen))
internal.WriteCString(uintptr(fieldNamePtr), fieldName)
return envGet(proxyPtr, uint32(uintptr(fieldNamePtr)))
}
// materialize the String content referenced
func GetString(proxyPtr uint32) string {
var resultPtr = envGetString(proxyPtr)
var result = internal.ReadCString(resultPtr)
internal.Free(unsafe.Pointer(uintptr(resultPtr)))
return result
}
// materialize the Boolean content referenced
func GetBool(proxyPtr uint32) bool {
return envGetBool(proxyPtr) > 0
}
// materialize the Bytes content referenced
func GetBytes(proxyPtr uint32) []byte {
var resultPtr = envGetBytes(proxyPtr)
var result = internal.ReadCString(resultPtr)
internal.Free(unsafe.Pointer(uintptr(resultPtr)))
return []byte(result)
}
// materialize the Float32 content referenced
func GetFloat32(proxyPtr uint32) float32 {
return envGetFloat32(proxyPtr)
}
// materialize the Float64 content referenced
func GetFloat64(proxyPtr uint32) float64 {
return envGetFloat64(proxyPtr)
}
// materialize the Int16 content referenced
func GetInt16(proxyPtr uint32) int16 {
return int16(envGetInt16(proxyPtr))
}
// materialize the Int32 content referenced
func GetInt32(proxyPtr uint32) int32 {
return envGetInt32(proxyPtr)
}
// materialize the Int64 content referenced
func GetInt64(proxyPtr uint32) int64 {
return envGetInt64(proxyPtr)
}
// materialize the Int8 content referenced
func GetInt8(proxyPtr uint32) int8 {
return int8(envGetInt8(proxyPtr))
}
// check whenever the referenced content is Null
func IsNull(valuePtr uint32) bool {
return (envIsNull(valuePtr) > 0)
}
// set a Boolean content for the Debezium Host
func SetBool(value bool) uint32 {
var valuePtr = internal.Malloc(1)
if value {
*(*byte)(unsafe.Pointer(uintptr(valuePtr))) = 1
} else {
*(*byte)(unsafe.Pointer(uintptr(valuePtr))) = 0
}
return envSetBool(uint32(uintptr(valuePtr)))
}
// set a Null content for the Debezium Host
func SetNull() uint32 {
return envSetNull()
}
// set a String content for the Debezium Host
func SetString(value string) uint32 {
var valueLen = len(value) + 1
var valuePtr = internal.Malloc(uintptr(valueLen))
internal.WriteCString(uintptr(valuePtr), value)
return envSetString(uint32(uintptr(valuePtr)))
}
//go:wasm-module env
//export get_string
func envGetString(proxyPtr uint32) uint32
//go:wasm-module env
//export set_null
func envSetNull() uint32
//go:wasm-module env
//export is_null
func envIsNull(valuePtr uint32) uint32
//go:wasm-module env
//export set_string
func envSetString(valuePtr uint32) uint32
//go:wasm-module env
//export set_bool
func envSetBool(valuePtr uint32) uint32
//go:wasm-module env
//export get
func envGet(proxyPtr, fieldNamePtr uint32) uint32
//go:wasm-module env
//export get_bool
func envGetBool(proxyPtr uint32) uint32
//go:wasm-module env
//export get_bytes
func envGetBytes(proxyPtr uint32) uint32
//go:wasm-module env
//export get_float32
func envGetFloat32(proxyPtr uint32) float32
//go:wasm-module env
//export get_float64
func envGetFloat64(proxyPtr uint32) float64
//go:wasm-module env
//export get_int16
func envGetInt16(proxyPtr uint32) uint32
//go:wasm-module env
//export get_int32
func envGetInt32(proxyPtr uint32) int32
//go:wasm-module env
//export get_int64
func envGetInt64(proxyPtr uint32) int64
//go:wasm-module env
//export get_int8
func envGetInt8(proxyPtr uint32) uint32