Skip to content

Commit 1ecd604

Browse files
cosmo0920edsiper
authored andcommitted
Update documentation for creating msgpack payload on in_gdummy
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 84de722 commit 1ecd604

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

examples/in_gdummy/README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,21 @@ When Fluent Bit wants to collect logs from Golang input plugin, the input callba
4949
The 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
}

0 commit comments

Comments
 (0)