gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

rfc6587.go (943B)


      1 package format
      2 
      3 import (
      4 	"bufio"
      5 	"bytes"
      6 	"strconv"
      7 
      8 	"gopkg.in/mcuadros/go-syslog.v2/internal/syslogparser/rfc5424"
      9 )
     10 
     11 type RFC6587 struct{}
     12 
     13 func (f *RFC6587) GetParser(line []byte) LogParser {
     14 	return &parserWrapper{rfc5424.NewParser(line)}
     15 }
     16 
     17 func (f *RFC6587) GetSplitFunc() bufio.SplitFunc {
     18 	return rfc6587ScannerSplit
     19 }
     20 
     21 func rfc6587ScannerSplit(data []byte, atEOF bool) (advance int, token []byte, err error) {
     22 	if atEOF && len(data) == 0 {
     23 		return 0, nil, nil
     24 	}
     25 
     26 	if i := bytes.IndexByte(data, ' '); i > 0 {
     27 		pLength := data[0:i]
     28 		length, err := strconv.Atoi(string(pLength))
     29 		if err != nil {
     30 			if string(data[0:1]) == "<" {
     31 				// Assume this frame uses non-transparent-framing
     32 				return len(data), data, nil
     33 			}
     34 			return 0, nil, err
     35 		}
     36 		end := length + i + 1
     37 		if len(data) >= end {
     38 			// Return the frame with the length removed
     39 			return end, data[i+1 : end], nil
     40 		}
     41 	}
     42 
     43 	// Request more data
     44 	return 0, nil, nil
     45 }