1
0
mirror of https://github.com/netsampler/goflow2.git synced 2024-05-06 15:54:52 +00:00

Merge pull request #68 from netsampler/bugfix/enricher-2

Bugfix: issues when reading a partial chunk of protobuf from stdin
This commit is contained in:
Louis
2022-01-24 20:34:11 -08:00
committed by GitHub

View File

@ -147,26 +147,28 @@ func main() {
rdr := bufio.NewReader(os.Stdin) rdr := bufio.NewReader(os.Stdin)
msg := &flowmessage.FlowMessageExt{} msg := &flowmessage.FlowMessageExt{}
msgLen := make([]byte, binary.MaxVarintLen64) lenBufSize := binary.MaxVarintLen64
lenBufSize := len(msgLen)
for { for {
n, err := rdr.Read(msgLen) msgLen, err := rdr.Peek(lenBufSize)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
log.Error(err) log.Error(err)
continue continue
} }
len, vn := proto.DecodeVarint(msgLen[0:n]) l, vn := proto.DecodeVarint(msgLen)
if len == 0 { if l == 0 {
continue continue
} }
line := make([]byte, len) _, err = rdr.Discard(vn)
if vn < lenBufSize { if err != nil {
copy(line[0:lenBufSize-vn], msgLen[vn:lenBufSize]) log.Error(err)
continue
} }
n, err = io.ReadFull(rdr, line[lenBufSize-vn:]) line := make([]byte, l)
_, err = io.ReadFull(rdr, line)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
log.Error(err) log.Error(err)
continue continue