blob: 813afc51ba258309dadd3cc900a723d8214e42dc (
plain)
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
|
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() {}
|