File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -49,8 +49,21 @@ When Fluent Bit wants to collect logs from Golang input plugin, the input callba
4949The callback will send a raw buffer of msgpack data with it proper bytes length into Fluent Bit core.
5050
5151``` go
52+ import " reflect" // Import reflect package.
53+
54+ // Operate safe payload creation.
55+ func MakePayload (packed []byte ) (**C .void , int ) {
56+ var payload **C.void
57+
58+ length := len (packed)
59+ hdr := (*reflect.SliceHeader )(unsafe.Pointer (&payload))
60+ hdr.Data = uintptr (unsafe.Pointer (&packed))
61+ hdr.Len = length
62+
63+ return payload, length
64+ }
5265// export FLBPluginInputCallback
53- func FLBPluginInputCallback (data *unsafe . Pointer , size *C .size_t ) int {
66+ func FLBPluginInputCallback (data ** C . void , size *C .size_t ) int {
5467 now := time.Now ()
5568 // To handle nanosecond precision on Golang input plugin, you must wrap up time instances with input.FLBTime type.
5669 flb_time := input.FLBTime {now}
@@ -61,7 +74,9 @@ func FLBPluginInputCallback(data *unsafe.Pointer, size *C.size_t) int {
6174 // Some encoding logs to msgpack payload stuffs.
6275 // It needs to Wait for some period on Golang input plugin side, until the new records are emitted.
6376
64- *data = unsafe.Pointer (&packed[0 ])
77+ payload , length := MakePayload (packed)
78+
79+ *data = *payload
6580 *size = C.size_t (len (packed))
6681 return input.FLB_OK
6782}
You can’t perform that action at this time.
0 commit comments