diff --git a/input_file.go b/input_file.go index 0a38428..1fdf0f1 100644 --- a/input_file.go +++ b/input_file.go @@ -4,7 +4,6 @@ import ( "log" "os" "bufio" - "bytes" "strconv" "time" ) @@ -51,28 +50,12 @@ func (i *FileInput) String() string { return "File input: " + i.path } -func scanSeparator(data []byte, atEOF bool) (advance int, token []byte, err error) { - if atEOF && len(data) == 0 { - return 0, nil, nil - } - - if i := bytes.Index(data, []byte(fileSeparator)); i >= 0 { - // We have a full newline-terminated line. - return i + len(fileSeparator), data[0:i], nil - } - - if atEOF { - return len(data), data, nil - } - return 0, nil, nil -} - func (i *FileInput) emit() { var lastTime int64 // reader := bufio.NewReader(conn) scanner := bufio.NewScanner(i.file) - scanner.Split(scanSeparator) + scanner.Split(payloadScanner) for scanner.Scan() { buf := scanner.Bytes() diff --git a/output_file.go b/output_file.go index d01f05f..e8b0d86 100644 --- a/output_file.go +++ b/output_file.go @@ -31,15 +31,13 @@ func (o *FileOutput) init(path string) { } } -var fileSeparator = "\nšŸµšŸ™ˆšŸ™‰\n" - func (o *FileOutput) Write(data []byte) (n int, err error) { if !isOriginPayload(data) { return len(data), nil } o.file.Write(data) - o.file.Write([]byte(fileSeparator)) + o.file.Write([]byte(payloadSeparator)) return len(data), nil } diff --git a/protocol.go b/protocol.go index 9b8cc1a..a55f6b3 100644 --- a/protocol.go +++ b/protocol.go @@ -23,6 +23,24 @@ func uuid() []byte { return uuid } +var payloadSeparator = "\nšŸµšŸ™ˆšŸ™‰\n" + +func payloadScanner(data []byte, atEOF bool) (advance int, token []byte, err error) { + if atEOF && len(data) == 0 { + return 0, nil, nil + } + + if i := bytes.Index(data, []byte(payloadSeparator)); i >= 0 { + // We have a full newline-terminated line. + return i + len([]byte(payloadSeparator)), data[0:i], nil + } + + if atEOF { + return len(data), data, nil + } + return 0, nil, nil +} + // Timing is request start or round-trip time, depending on payloadType func payloadHeader(payloadType int, uuid []byte, timing int64) (header []byte) {