decoder

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsFDOp

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

AsFDOp is a deode operation that writes fields to metrics

func AsF

func AsF(name string) *AsFDOp

AsF answers a decode operation that will output a field into the open metric with the given name

func (*AsFDOp) AsF

func (op *AsFDOp) AsF(name string) DirectiveOp

func (*AsFDOp) AsT

func (op *AsFDOp) AsT(name string) DirectiveOp

func (*AsFDOp) Set

func (op *AsFDOp) Set(ptr interface{}) *SetDOp

type AsTDOp

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

AsTDOp is a deode operation that writes tags to metrics

func AsT

func AsT(name string) *AsTDOp

AsT answers a decode operation that will output a tag into the open metric with the given name

func (*AsTDOp) AsF

func (op *AsTDOp) AsF(name string) DirectiveOp

func (*AsTDOp) AsT

func (op *AsTDOp) AsT(name string) DirectiveOp

func (*AsTDOp) Set

func (op *AsTDOp) Set(ptr interface{}) *SetDOp

type AsTimestampDOp

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

AsTimestampDOp is a deode operation that sets the timestamp on the metric

func AsTimestamp

func AsTimestamp() *AsTimestampDOp

AsTimestamp answers a decode operation that will set the tiemstamp on the metric

func (*AsTimestampDOp) AsF

func (op *AsTimestampDOp) AsF(name string) DirectiveOp

func (*AsTimestampDOp) AsT

func (op *AsTimestampDOp) AsT(name string) DirectiveOp

func (*AsTimestampDOp) Set

func (op *AsTimestampDOp) Set(ptr interface{}) *SetDOp

type BreakIfDOp

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

BreakIfDOp is a decode operation that will break the current outer iteration

func (*BreakIfDOp) AsF

func (op *BreakIfDOp) AsF(name string) DirectiveOp

func (*BreakIfDOp) AsT

func (op *BreakIfDOp) AsT(name string) DirectiveOp

func (*BreakIfDOp) Set

func (op *BreakIfDOp) Set(ptr interface{}) *SetDOp

type BytesToDOp

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

BytesToDOp is a decode operation that will transform []byte to interface{} according to a suppied function

func BytesTo

func BytesTo(len int, fn func([]byte) interface{}) *BytesToDOp

BytesTo answers a decode operation that transforms a []bytes to a interface{} via the supplied fn

func (*BytesToDOp) AsF

func (op *BytesToDOp) AsF(name string) DirectiveOp

func (*BytesToDOp) AsT

func (op *BytesToDOp) AsT(name string) DirectiveOp

func (*BytesToDOp) Set

func (op *BytesToDOp) Set(ptr interface{}) *SetDOp

type BytesToStrDOp

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

BytesToStrDOp is a decode operation that transforms []bytes to strings

func BytesToStr

func BytesToStr(len int, fn func([]byte) string) *BytesToStrDOp

BytesToStr answers a decode operation that transforms a []bytes to a string via the supplied fn

func (*BytesToStrDOp) AsF

func (op *BytesToStrDOp) AsF(name string) DirectiveOp

func (*BytesToStrDOp) AsT

func (op *BytesToStrDOp) AsT(name string) DirectiveOp

func (*BytesToStrDOp) Set

func (op *BytesToStrDOp) Set(ptr interface{}) *SetDOp

type BytesToU32DOp

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

BytesToU32DOp is a decode operation that transforms a []byte to a uint32

func BytesToU32

func BytesToU32(len int, fn func([]byte) uint32) *BytesToU32DOp

BytesToU32 answers a decode operation that transforms a []bytes to an uint32 via the supplied fn

func (*BytesToU32DOp) AsF

func (op *BytesToU32DOp) AsF(name string) DirectiveOp

func (*BytesToU32DOp) AsT

func (op *BytesToU32DOp) AsT(name string) DirectiveOp

func (*BytesToU32DOp) Set

func (op *BytesToU32DOp) Set(ptr interface{}) *SetDOp

type CaseValueDirective

type CaseValueDirective interface {
	Directive
	Equals(interface{}) bool
}

CaseValueDirective is a decode directive that also has a switch/case test

func Case

func Case(caseValue interface{}, dd Directive) CaseValueDirective

Case answers a directive to be used within a Switch clause of a U32 directive

func DefaultCase

func DefaultCase(dd Directive) CaseValueDirective

DefaultCase answers a case decoder directive that can be used as the default, catch all, of a Switch

type DecodeContext

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

DecodeContext provides context for the decoding of a packet and primarily acts as a repository for metrics that are collected during the packet decode process

func NewDecodeContext

func NewDecodeContext() *DecodeContext

NewDecodeContext ansewers a new Decode Contect to support the process of decoding

func (*DecodeContext) Decode

func (dc *DecodeContext) Decode(dd Directive, buffer *bytes.Buffer) error

Decode initiates the decoding of the supplied buffer according to the root decode directive that is provided

func (*DecodeContext) GetMetrics

func (dc *DecodeContext) GetMetrics() []telegraf.Metric

GetMetrics answers the metrics that have been collected during the packet decode

type Directive

type Directive interface {

	// Execute performs the function of the decode directive. If DecodeContext is nil then the
	// ask is to check that a subsequent execution (with non nill DecodeContext) is expted to work.
	Execute(*bytes.Buffer, *DecodeContext) error
}

Directive is a Decode Directive, the basic building block of a decoder

func CloseMetric

func CloseMetric() Directive

CloseMetric answers a directive that close the current metrics

func ErrorDirective

func ErrorDirective() Directive

ErrorDirective answers a decode directive that will generate an error

func Nop

func Nop() Directive

Nop answer a decode directive that is the null, benign, deocder

func Notify

func Notify(fn func()) Directive

Notify answers a decode directive that will notify the supplied function upon execution

func OpenMetric

func OpenMetric(name string) Directive

OpenMetric answers a directive that opens a new metrics for collecting tags and fields

func Seq

func Seq(decoders ...Directive) Directive

Seq ansers a directive that sequentially executes a list of provided directives

func SeqOf

func SeqOf(decoders []Directive) Directive

type DirectiveOp

type DirectiveOp interface {
	// contains filtered or unexported methods
}

DirectiveOp are operations that are performed on values that have been decoded. They are expected to be chained together, in a flow programming style, and the Decode Directive that they are assigned to then walks back up the linked list to find the root operation that will then be performed (passing the value down through various transformations)

type ErrorDOp

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

ErrorDOp is a decode operation that will generate an error

func ErrorOp

func ErrorOp(errorOnTestProcess bool) *ErrorDOp

ErrorOp answers a decode operation that will generate an error

func (*ErrorDOp) AsF

func (op *ErrorDOp) AsF(name string) DirectiveOp

func (*ErrorDOp) AsT

func (op *ErrorDOp) AsT(name string) DirectiveOp

func (*ErrorDOp) Set

func (op *ErrorDOp) Set(ptr interface{}) *SetDOp

type IterOption

type IterOption struct {
	EOFTerminateIter                   bool
	RemainingToGreaterEqualOrTerminate uint32
}

type SetDOp

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

SetDOp is a decode operation that will Set a pointer to a value to be the value processed

func Set

func Set(ptr interface{}) *SetDOp

Set answers a decode operation that will set the supplied *value to the value passed through the operation

func (*SetDOp) AsF

func (op *SetDOp) AsF(name string) DirectiveOp

func (*SetDOp) AsT

func (op *SetDOp) AsT(name string) DirectiveOp

func (*SetDOp) Set

func (op *SetDOp) Set(ptr interface{}) *SetDOp

type U16AssertDOp

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

U16AssertDOp is a decode operation that asserts a particular uint32 value

func U16Assert

func U16Assert(fn func(v uint16) bool, fmtStr string) *U16AssertDOp

func (*U16AssertDOp) AsF

func (op *U16AssertDOp) AsF(name string) DirectiveOp

func (*U16AssertDOp) AsT

func (op *U16AssertDOp) AsT(name string) DirectiveOp

func (*U16AssertDOp) Set

func (op *U16AssertDOp) Set(ptr interface{}) *SetDOp

type U16ToStrDOp

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

U16ToStrDOp is a decode operation that transforms a uint16 to a string

func MapU16ToStr

func MapU16ToStr(m map[uint16]string) *U16ToStrDOp

MapU16ToStr answers a decode operation that maps an uint16 to a string via the supplied map

func U16ToStr

func U16ToStr(fn func(uint16) string) *U16ToStrDOp

U16ToStr answers a decode operation that transforms a uint16 to a string via the supplied fn

func (*U16ToStrDOp) AsF

func (op *U16ToStrDOp) AsF(name string) DirectiveOp

func (*U16ToStrDOp) AsT

func (op *U16ToStrDOp) AsT(name string) DirectiveOp

func (*U16ToStrDOp) Set

func (op *U16ToStrDOp) Set(ptr interface{}) *SetDOp

type U16ToU16DOp

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

U16ToU16DOp is a decode operation that transfirms one uint16 to another uint16

func U16ToU16

func U16ToU16(fn func(uint16) uint16) *U16ToU16DOp

U16ToU16 answers a decode operation that transforms a uint16 to a uint16 via the supplied fn

func (*U16ToU16DOp) AsF

func (op *U16ToU16DOp) AsF(name string) DirectiveOp

func (*U16ToU16DOp) AsT

func (op *U16ToU16DOp) AsT(name string) DirectiveOp

func (*U16ToU16DOp) Set

func (op *U16ToU16DOp) Set(ptr interface{}) *SetDOp

type U32AssertDOp

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

U32AssertDOp is a decode operation that asserts a particular uint32 value

func U32Assert

func U32Assert(fn func(v uint32) bool, fmtStr string) *U32AssertDOp

U32Assert answers a decode operation that will assert the uint32 is a particulr value or generate an error

func (*U32AssertDOp) AsF

func (op *U32AssertDOp) AsF(name string) DirectiveOp

func (*U32AssertDOp) AsT

func (op *U32AssertDOp) AsT(name string) DirectiveOp

func (*U32AssertDOp) Set

func (op *U32AssertDOp) Set(ptr interface{}) *SetDOp

type U32ToStrDOp

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

U32ToStrDOp is a decod eoperation that transforms a uint32 to a string

func MapU32ToStr

func MapU32ToStr(m map[uint32]string) *U32ToStrDOp

MapU32ToStr answers a decode operation that maps an uint32 to a string via the supplied map

func U32ToStr

func U32ToStr(fn func(uint32) string) *U32ToStrDOp

U32ToStr answers a decode operation that transforms a uint32 to a string via the supplied fn

func (*U32ToStrDOp) AsF

func (op *U32ToStrDOp) AsF(name string) DirectiveOp

func (*U32ToStrDOp) AsT

func (op *U32ToStrDOp) AsT(name string) DirectiveOp

func (*U32ToStrDOp) BreakIf

func (op *U32ToStrDOp) BreakIf(value string) *BreakIfDOp

BreakIf answers a BreakIf operation that will break the current decode operation chain, without an error, if the value processed is the supplied value

func (*U32ToStrDOp) Set

func (op *U32ToStrDOp) Set(ptr interface{}) *SetDOp

type U32ToU32DOp

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

U32ToU32DOp is a deode operation that can process U32 to U32

func U32ToU32

func U32ToU32(fn func(uint32) uint32) *U32ToU32DOp

U32ToU32 answers a decode operation that transforms a uint32 to a uint32 via the supplied fn

func (*U32ToU32DOp) AsF

func (op *U32ToU32DOp) AsF(name string) DirectiveOp

func (*U32ToU32DOp) AsT

func (op *U32ToU32DOp) AsT(name string) DirectiveOp

func (*U32ToU32DOp) Set

func (op *U32ToU32DOp) Set(ptr interface{}) *SetDOp

func (*U32ToU32DOp) ToString

func (op *U32ToU32DOp) ToString(fn func(uint32) string) *U32ToStrDOp

ToString answers a U32ToStr decode operation that will transform this output of thie U32ToU32 into a string

type ValueDirective

type ValueDirective interface {
	Directive

	// Switch attaches a set of conditional decode directives downstream of this decode directive
	Switch(paths ...CaseValueDirective) ValueDirective

	// Iter attaches a single downstream decode directive that will be executed repeatedly according to the iteration count
	Iter(maxIterations uint32, dd Directive, iterOptions ...IterOption) ValueDirective

	// Encapsulated will form a new buffer of the encapsulated length and pass that buffer on to the downsstream decode directive
	Encapsulated(maxSize uint32, dd Directive) ValueDirective

	// Ref records this decode directive in the passed reference
	Ref(*interface{}) ValueDirective

	// Do attaches a Decode Operation - these are uses of the decoded information to perform work on, transform, write out etc.
	Do(ddo DirectiveOp) ValueDirective
}

ValueDirective is a decode directive that extracts some data from the packet, an integer or byte maybe, which it then processes by using it, for example, as the counter for the number of iterations to perform of downstream decode directives.

A ValueDirective can be used to either Switch, Iter(ate), Encapsulate or Do mutually exclusively.

func Bytes

func Bytes(len int) ValueDirective

Bytes answers a value directive that will decode the specified number (len) of bytes from the packet

func Ref

func Ref(target interface{}) ValueDirective

Ref answers a decoder that reuses, through referal, an existing U32 directive

func U16

func U16() ValueDirective

U16 answers a directive for 32bit Unsigned Integers

func U16Value

func U16Value(value *uint16) ValueDirective

U16Value answers a directive that doesn't actually decode itself but reused a value previously decoded of type uint16

func U32

func U32() ValueDirective

U32 answers a directive for 32bit Unsigned Integers

func U64

func U64() ValueDirective

U64 answers a directive for 64bit Unsigned Integers

func U8

func U8() ValueDirective

U8 answers a directive for 8bit Unsigned Integers

Jump to

Keyboard shortcuts

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