forked from TarsCloud/TarsGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.go
55 lines (43 loc) · 921 Bytes
/
message.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
package tars
import (
"time"
"github.com/TarsCloud/TarsGo/tars/protocol/res/requestf"
)
// HashType is the hash type
type HashType int
// HashType enum
const (
ModHash HashType = iota
ConsistentHash
)
// Message is a struct contains servant information
type Message struct {
Req *requestf.RequestPacket
Resp *requestf.ResponsePacket
Ser *ServantProxy
Adp *AdapterProxy
BeginTime int64
EndTime int64
Status int32
hashCode uint32
hashType HashType
isHash bool
}
// Init define the begintime
func (m *Message) Init() {
m.BeginTime = time.Now().UnixNano() / 1e6
}
// End define the endtime
func (m *Message) End() {
m.EndTime = time.Now().UnixNano() / 1e6
}
// Cost calculate the cost time
func (m *Message) Cost() int64 {
return m.EndTime - m.BeginTime
}
// SetHash set hash code
func (m *Message) SetHash(code uint32, h HashType) {
m.hashCode = code
m.hashType = h
m.isHash = true
}