mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Refactor #308
This commit is contained in:
+18
-3
@@ -42,13 +42,24 @@ func payloadScanner(data []byte, atEOF bool) (advance int, token []byte, err err
|
||||
}
|
||||
|
||||
// Timing is request start or round-trip time, depending on payloadType
|
||||
func payloadHeader(payloadType byte, uuid []byte, timing int64) (header []byte) {
|
||||
sTime := strconv.FormatInt(timing, 10)
|
||||
func payloadHeader(payloadType byte, uuid []byte, timing int64, latency int64) (header []byte) {
|
||||
var sTime, sLatency string
|
||||
|
||||
sTime = strconv.FormatInt(timing, 10)
|
||||
if latency != -1 {
|
||||
sLatency = strconv.FormatInt(latency, 10)
|
||||
}
|
||||
|
||||
//Example:
|
||||
// 3 f45590522cd1838b4a0d5c5aab80b77929dea3b3 1231\n
|
||||
// `+ 1` indicates space characters or end of line
|
||||
header = make([]byte, 1+1+len(uuid)+1+len(sTime)+1)
|
||||
headerLen := 1 + 1 + len(uuid) + 1 + len(sTime) + 1
|
||||
|
||||
if latency != -1 {
|
||||
headerLen += len(sLatency) + 1
|
||||
}
|
||||
|
||||
header = make([]byte, headerLen)
|
||||
header[0] = payloadType
|
||||
header[1] = ' '
|
||||
header[2+len(uuid)] = ' '
|
||||
@@ -57,6 +68,10 @@ func payloadHeader(payloadType byte, uuid []byte, timing int64) (header []byte)
|
||||
copy(header[2:], uuid)
|
||||
copy(header[3+len(uuid):], sTime)
|
||||
|
||||
if latency != -1 {
|
||||
copy(header[4+len(uuid)+len(sTime):], sLatency)
|
||||
}
|
||||
|
||||
return header
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user