diff options
Diffstat (limited to '')
-rw-r--r-- | fluent-bit/tests/runtime/wasm/go/append_tag.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/fluent-bit/tests/runtime/wasm/go/append_tag.go b/fluent-bit/tests/runtime/wasm/go/append_tag.go new file mode 100644 index 00000000..813afc51 --- /dev/null +++ b/fluent-bit/tests/runtime/wasm/go/append_tag.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "time" + "unsafe" + + "github.com/valyala/fastjson" +) + +//export filter_append_tag +func filter_append_tag(tag *uint8, tag_len uint, time_sec uint, time_nsec uint, record *uint8, record_len uint) *uint8 { + btag := unsafe.Slice(tag, tag_len) // Note, requires Go 1.17+ (tinygo 0.20+) + brecord := unsafe.Slice(record, record_len) + _ = time.Unix(int64(time_sec), int64(time_nsec)) + + br := string(brecord) + var p fastjson.Parser + value, err := p.Parse(br) + if err != nil { + fmt.Println(err) + return nil + } + obj, err := value.Object() + if err != nil { + fmt.Println(err) + return nil + } + + var arena fastjson.Arena + obj.Set("tag", arena.NewString(string(btag))) + s := obj.String() + s += string(rune(0)) // Note: explicit null terminator. + rv := []byte(s) + + return &rv[0] +} + +func main() {} |