-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebezium.go
More file actions
102 lines (80 loc) · 2.43 KB
/
Copy pathdebezium.go
File metadata and controls
102 lines (80 loc) · 2.43 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
101
102
package debezium
import (
"strconv"
"unsafe"
"github.com/andreaTP/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 Numeric content referenced
func GetInt(proxyPtr uint32) uint32 {
return envGetInt(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)))
}
// set a Numeric content for the Debezium Host
func SetInt(value uint32) uint32 {
bs := []byte(strconv.Itoa(int(value)))
var valuePtr = internal.Malloc(uintptr(len(bs) + 1))
internal.WriteCString(uintptr(valuePtr), string(bs))
return envSetInt(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_int
func envSetInt(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_int
func envGetInt(proxyPtr uint32) uint32