MCPcopy Create free account
hub / github.com/bitly/statsdaemon / Next

Method Next

statsdaemon.go:385–422  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

383}
384
385func (mp *MsgParser) Next() (*Packet, bool) {
386 buf := mp.buffer
387
388 for {
389 line, rest := mp.lineFrom(buf)
390
391 if line != nil {
392 mp.buffer = rest
393 return parseLine(line), true
394 }
395
396 if mp.done {
397 if len(rest) > 0 {
398 return parseLine(rest), false
399 }
400 return nil, false
401 }
402
403 // for udp, each message independent
404 // for tcp, copy to front and append
405 // unless no '\n' in entire TCP_READ_SIZE
406 idx := 0
407 if mp.partialReads && len(buf) < TCP_READ_SIZE {
408 idx = len(buf)
409 copy(mp.newbuf, buf)
410 }
411 buf = mp.newbuf
412
413 n, err := mp.reader.Read(buf[idx:])
414 buf = buf[:idx+n]
415 if err != nil {
416 if err != io.EOF {
417 log.Printf("ERROR: %s", err)
418 }
419 mp.done = true
420 }
421 }
422}
423
424func (mp *MsgParser) lineFrom(input []byte) ([]byte, []byte) {
425 split := bytes.SplitN(input, []byte("\n"), 2)

Callers 5

parseToFunction · 0.80
TestParseLineMiscFunction · 0.80
checkTwoPacketsFunction · 0.80
BenchmarkMsgParserUDPFunction · 0.80
BenchmarkMsgParserTCPFunction · 0.80

Calls 3

lineFromMethod · 0.95
parseLineFunction · 0.85
ReadMethod · 0.45

Tested by 4

TestParseLineMiscFunction · 0.64
checkTwoPacketsFunction · 0.64
BenchmarkMsgParserUDPFunction · 0.64
BenchmarkMsgParserTCPFunction · 0.64