forked from Meituan-Dianping/cat-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
encoder.go
39 lines (34 loc) · 877 Bytes
/
encoder.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
package message
import (
"bytes"
)
const (
defaultThreadGroupName = ""
defaultThreadId = "0"
defaultThreadName = ""
)
type Encoder interface {
EncodeHeader(*bytes.Buffer, *Header) error
EncodeMessage(*bytes.Buffer, Messager) error
EncodeTransaction(*bytes.Buffer, *Transaction) error
EncodeEvent(*bytes.Buffer, *Event) error
EncodeHeartbeat(*bytes.Buffer, *Heartbeat) error
EncodeMetric(*bytes.Buffer, *Metric) error
}
type encoderBase struct {
}
func encodeMessage(encoder Encoder, buf *bytes.Buffer, message Messager) (err error) {
switch m := message.(type) {
case *Transaction:
return encoder.EncodeTransaction(buf, m)
case *Event:
return encoder.EncodeEvent(buf, m)
case *Heartbeat:
return encoder.EncodeHeartbeat(buf, m)
case *Metric:
return encoder.EncodeMetric(buf, m)
default:
// TODO unsupported message type.
return
}
}