-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappend_key_value.go
94 lines (69 loc) · 2.03 KB
/
append_key_value.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package fluentlog
import (
"fmt"
"github.com/webmafia/fluentlog/internal"
"github.com/webmafia/fluentlog/pkg/msgpack"
)
func appendKeyValue(dst []byte, key string, value any) ([]byte, uint8) {
switch val := value.(type) {
case KeyValueAppender:
return val.AppendKeyValue(dst, key)
case internal.TextAppender:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendTextAppender(dst, val)
case fmt.Stringer:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendString(dst, val.String())
case []byte:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendBinary(dst, val)
case bool:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendBool(dst, val)
case float32:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendFloat(dst, float64(val))
case float64:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendFloat(dst, val)
case int:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendInt(dst, int64(val))
case int8:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendInt(dst, int64(val))
case int16:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendInt(dst, int64(val))
case int32:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendInt(dst, int64(val))
case int64:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendInt(dst, val)
case uint:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendUint(dst, uint64(val))
case uint8:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendUint(dst, uint64(val))
case uint16:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendUint(dst, uint64(val))
case uint32:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendUint(dst, uint64(val))
case uint64:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendUint(dst, val)
case string:
dst = msgpack.AppendString(dst, key)
dst = msgpack.AppendString(dst, val)
default:
return dst, 0
}
return dst, 1
}
type KeyValueAppender interface {
AppendKeyValue(dst []byte, key string) ([]byte, byte)
}