-
Notifications
You must be signed in to change notification settings - Fork 349
/
sls_logs.pb.helper.go
53 lines (44 loc) · 1.05 KB
/
sls_logs.pb.helper.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
package protocol
import (
"fmt"
"github.com/gogo/protobuf/proto"
)
func CloneLog(log *Log) *Log {
cloneLog := &Log{
Time: log.Time,
TimeNs: log.TimeNs,
Contents: make([]*Log_Content, len(log.Contents), cap(log.Contents)),
}
for i, content := range log.Contents {
cloneLog.Contents[i] = &Log_Content{
Key: content.Key,
Value: content.Value,
}
}
return cloneLog
}
func SetLogTime(log *Log, second uint32) {
log.Time = second
}
func SetLogTimeWithNano(log *Log, second uint32, nanosecond uint32) {
log.Time = second
log.TimeNs = &nanosecond
}
type Codec struct{}
func (Codec) Marshal(v interface{}) ([]byte, error) {
vv, ok := v.(proto.Message)
if !ok {
return nil, fmt.Errorf("failed to marshal, message is %T, want proto.Message", v)
}
return proto.Marshal(vv)
}
func (Codec) Unmarshal(data []byte, v interface{}) error {
vv, ok := v.(proto.Message)
if !ok {
return fmt.Errorf("failed to unmarshal, message is %T, want proto.Message", v)
}
return proto.Unmarshal(data, vv)
}
func (Codec) Name() string {
return "proto"
}