File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import "C"
44import (
55 "fmt"
66 "time"
7+ "reflect"
78 "unsafe"
89
910 "github.com/fluent/fluent-bit-go/input"
@@ -24,8 +25,19 @@ func FLBPluginInit(plugin unsafe.Pointer) int {
2425 return input .FLB_OK
2526}
2627
28+ func MakePayload (packed []byte ) (* * C.void , int ) {
29+ var payload * * C.void
30+
31+ length := len (packed )
32+ hdr := (* reflect .SliceHeader )(unsafe .Pointer (& payload ))
33+ hdr .Data = uintptr (unsafe .Pointer (& packed ))
34+ hdr .Len = length
35+
36+ return payload , length
37+ }
38+
2739//export FLBPluginInputCallback
28- func FLBPluginInputCallback (data * unsafe. Pointer , size * C.size_t ) int {
40+ func FLBPluginInputCallback (data * * C. void , size * C.size_t ) int {
2941 now := time .Now ()
3042 flb_time := input.FLBTime {now }
3143 message := map [string ]string {"message" : "dummy" }
@@ -39,8 +51,10 @@ func FLBPluginInputCallback(data *unsafe.Pointer, size *C.size_t) int {
3951 return input .FLB_ERROR
4052 }
4153
42- * data = unsafe .Pointer (& packed [0 ])
43- * size = C .size_t (len (packed ))
54+ payload , length := MakePayload (packed )
55+
56+ * data = * payload
57+ * size = C .size_t (length )
4458 // For emitting interval adjustment.
4559 time .Sleep (1000 * time .Millisecond )
4660
You can’t perform that action at this time.
0 commit comments