decoder

package
v0.0.0-...-3dd6856 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TRUNCATED = []byte("...TRUNCATED...")

TRUNCATED is the warning we add at the beginning or/and at the end of a truncated message

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	InputChan  chan *Input
	OutputChan chan *message.Message
	// contains filtered or unexported fields
}

Decoder splits raw data into lines and passes them to a lineHandler that emits outputs

func InitializeDecoder

func InitializeDecoder(source *config.LogSource, parser parser.Parser) *Decoder

InitializeDecoder returns a properly initialized Decoder

func New

func New(InputChan chan *Input, OutputChan chan *message.Message, lineHandler LineHandler) *Decoder

New returns an initialized Decoder

func (*Decoder) Start

func (d *Decoder) Start()

Start starts the Decoder

func (*Decoder) Stop

func (d *Decoder) Stop()

Stop stops the Decoder

type Input

type Input struct {
	// contains filtered or unexported fields
}

Input represents a list of bytes consumed by the Decoder

func NewInput

func NewInput(content []byte) *Input

NewInput returns a new input

type LineBuffer

type LineBuffer struct {
	// contains filtered or unexported fields
}

LineBuffer accumulates lines in buffer escaping all '\n' and accumulates the total number of bytes of all lines in line representation (line + '\n') in rawDataLen

func NewLineBuffer

func NewLineBuffer() *LineBuffer

NewLineBuffer returns a new LineBuffer

func (*LineBuffer) Add

func (l *LineBuffer) Add(line []byte)

Add stores line in buffer

func (*LineBuffer) AddEndOfLine

func (l *LineBuffer) AddEndOfLine()

AddEndOfLine stores an escaped '\n' in buffer

func (*LineBuffer) AddIncompleteLine

func (l *LineBuffer) AddIncompleteLine(line []byte)

AddIncompleteLine stores a chunck of line in buff

func (*LineBuffer) AddTruncate

func (l *LineBuffer) AddTruncate(line []byte)

AddTruncate stores TRUNCATED in buffer

func (*LineBuffer) Content

func (l *LineBuffer) Content() ([]byte, int)

Content returns the content in buffer and the length of the data that enabled to compute this content

func (*LineBuffer) IsEmpty

func (l *LineBuffer) IsEmpty() bool

IsEmpty returns true if buffer does not contain any line

func (*LineBuffer) Length

func (l *LineBuffer) Length() int

Length returns the length of buffer which might be different from rawDataLen because of escaped '\n'

func (*LineBuffer) Reset

func (l *LineBuffer) Reset()

Reset prepares buffer to receive new lines

type LineHandler

type LineHandler interface {
	Handle(content []byte)
	Start()
	Stop()
}

LineHandler handles byte slices to form line output

type MultiLineHandler

type MultiLineHandler struct {
	// contains filtered or unexported fields
}

MultiLineHandler reads lines from lineChan and uses lineBuffer to send them when a new line matches with re or flushTimer is fired

func NewMultiLineHandler

func NewMultiLineHandler(outputChan chan *message.Message, newContentRe *regexp.Regexp, flushTimeout time.Duration, parser parser.Parser) *MultiLineHandler

NewMultiLineHandler returns a new MultiLineHandler

func (*MultiLineHandler) Handle

func (h *MultiLineHandler) Handle(content []byte)

Handle forward lines to lineChan to process them

func (*MultiLineHandler) Start

func (h *MultiLineHandler) Start()

Start starts the handler

func (*MultiLineHandler) Stop

func (h *MultiLineHandler) Stop()

Stop stops the lineHandler from processing lines

type SingleLineHandler

type SingleLineHandler struct {
	// contains filtered or unexported fields
}

SingleLineHandler creates and forward outputs to outputChan from single-lines

func NewSingleLineHandler

func NewSingleLineHandler(outputChan chan *message.Message, parser parser.Parser) *SingleLineHandler

NewSingleLineHandler returns a new SingleLineHandler

func (*SingleLineHandler) Handle

func (h *SingleLineHandler) Handle(content []byte)

Handle trims leading and trailing whitespaces from content, and sends it as a new Line to lineChan.

func (*SingleLineHandler) Start

func (h *SingleLineHandler) Start()

Start starts the handler

func (*SingleLineHandler) Stop

func (h *SingleLineHandler) Stop()

Stop stops the handler from processing new lines

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL