forked from Phillipmartin/gopassivedns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessagepack.go
63 lines (58 loc) · 2.15 KB
/
messagepack.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
package main
import (
"github.com/vmihailenco/msgpack"
)
// logEntry is the same as dnsLog without some fields which are not required
// for fluentd outputs.
type logEntry struct {
Query_ID uint16 `msgpack:"query_id"`
Response_Code int `msgpack:"rcode"`
Question string `msgpack:"q"`
Question_Type string `msgpack:"qtype"`
Answer string `msgpack:"a"`
Answer_Type string `msgpack:"atype"`
TTL uint32 `msgpack:"ttl"`
Server string `msgpack:"dst"`
Client string `msgpack:"src"`
Timestamp string `msgpack:"tstamp"`
Elapsed int64 `msgpack:"elapsed"`
Client_Port string `msgpack:"sport"`
Level string `msgpack:"level,omitempty"` // syslog level omitted if empty
Length int `msgpack:"bytes"`
Proto string `msgpack:"protocol"`
Truncated bool `msgpack:"truncated"`
Authoritative_Answer bool `msgpack:"aa"`
Recursion_Desired bool `msgpack:"rd"`
Recursion_Available bool `msgpack:"ra"`
}
func (dle *dnsLogEntry) MarshalMsgpack() ([]byte, error) {
return msgpack.Marshal(&logEntry{
Query_ID: dle.Query_ID,
Response_Code: dle.Response_Code,
Question: dle.Question,
Question_Type: dle.Question_Type,
Answer: dle.Answer,
Answer_Type: dle.Answer_Type,
TTL: dle.TTL,
Server: dle.Server.String(),
Client: dle.Client.String(),
Timestamp: dle.Timestamp,
Elapsed: dle.Elapsed,
Client_Port: dle.Client_Port,
Level: dle.Level,
Length: dle.Length,
Proto: dle.Proto,
Truncated: dle.Truncated,
Authoritative_Answer: dle.Authoritative_Answer,
Recursion_Desired: dle.Recursion_Desired,
Recursion_Available: dle.Recursion_Available,
})
}
// Yet to be finished UnmarshalMsgpack method.
func (dle *dnsLogEntry) UnmarshalMsgpack(data []byte) error {
tmp := &dnsLogEntry{}
if err := msgpack.Unmarshal(data, &tmp); err != nil {
return err
}
return nil
}