Add support for tcp sessions

This commit is contained in:
Leonid Bugaev
2016-07-30 16:42:40 +03:00
parent 12287d8bae
commit a4826fcff9
8 changed files with 266 additions and 32 deletions
+19 -5
View File
@@ -13,14 +13,18 @@ const (
ReplayedResponsePayload = '3'
)
func uuid() []byte {
b := make([]byte, 20)
func randByte(len int) []byte {
b := make([]byte, len / 2)
rand.Read(b)
uuid := make([]byte, 40)
hex.Encode(uuid, b)
h := make([]byte, len)
hex.Encode(h, b)
return uuid
return h
}
func uuid() []byte {
return randByte(24)
}
var payloadSeparator = "\n🐵🙈🙉\n"
@@ -88,6 +92,16 @@ func payloadMeta(payload []byte) [][]byte {
return bytes.Split(payload[:headerSize], []byte{' '})
}
func payloadID(payload []byte) []byte {
idx := bytes.IndexByte(payload[2:], ' ')
if idx == -1 {
return []byte{}
}
return payload[2: 2 + idx]
}
func isOriginPayload(payload []byte) bool {
switch payload[0] {
case RequestPayload, ResponsePayload: