utils

package
v0.0.0-...-a807ae7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultWidth = 46 // 10 bytes per line on a []byte < 999

DefaultWidth defaults to a default screen dumps size

Variables

View Source
var ANSI_PATTERN = regexp.MustCompile("[\u001b\u009b][\\[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]")

ANSI_PATTERN source: https://github.com/chalk/ansi-regex/blob/main/index.js#L3

View Source
var AsciiBoxWriterDefault = NewAsciiBoxWriter()
View Source
var AsciiBoxWriterLight = NewAsciiBoxWriterWithCustomBorders(
	"╭",
	"╮",
	"┄",
	"┆",
	"╰",
	"╯",
)
View Source
var DebugAsciiBox bool

DebugAsciiBox set to true to get debug messages

View Source
var DebugHex bool

DebugHex set to true to get debug messages

Functions

func CleanupTimer

func CleanupTimer(timer *time.Timer)

CleanupTimer stops a timer and purges anything left in the channel

and is safe to call even if the channel has already been received

func CreateArrayContext

func CreateArrayContext(ctx context.Context, numItems int, curItem int) context.Context

CreateArrayContext creates a new context, which contains information on the size and the current position in the array.

func Dump

func Dump(data []byte, highlights ...int) string

Dump dumps a 56 char wide hex string

func DumpAnything

func DumpAnything(anything any) string

DumpAnything dumps anything as hex

func DumpAnythingFixedWidth

func DumpAnythingFixedWidth(anything any, charWidth int) string

DumpAnythingFixedWidth dumps anything as hex

func DumpFixedWidth

func DumpFixedWidth(data []byte, desiredCharWidth int, highlights ...int) string

DumpFixedWidth dumps hex as hex string. Min width of string returned is 18 up to supplied charWidth

func DuplicateIP

func DuplicateIP(ip net.IP) net.IP

func GenerateId

func GenerateId(localLog zerolog.Logger, numBytes int) string

func GetCurItemFromContext

func GetCurItemFromContext(ctx context.Context) int

GetCurItemFromContext helper to get access to the curItem value stored in the context.

func GetIPAddresses

func GetIPAddresses(localLog zerolog.Logger, ctx context.Context, netInterface net.Interface, useArpBasedScan bool) (foundIps chan net.IP, err error)

func GetLastItemFromContext

func GetLastItemFromContext(ctx context.Context) bool

GetLastItemFromContext helper to get access to the lastItem value which is calculated from data stored in the context.

func GetNumItemsFromContext

func GetNumItemsFromContext(ctx context.Context) int

GetNumItemsFromContext helper to get access to the numItems value stored in the context.

func GetSubgroupMatches

func GetSubgroupMatches(r *regexp.Regexp, query string) map[string]string

func IncrementIP

func IncrementIP(ip net.IP) net.IP

func InlineIf

func InlineIf[T any](test bool, a func() T, b func() T) T

InlineIf is basically a inline if like construct for golang

func Max

func Max[T constraints.Ordered](left, right T) T

func Min

func Min[T constraints.Ordered](left, right T) T

func PlcValueUint8ListToByteArray

func PlcValueUint8ListToByteArray(value values.PlcValue) []byte

func StrToBool

func StrToBool(str string) (bool, error)

func StrToInt32

func StrToInt32(str string) (int32, error)

func StrToString

func StrToString(s string) (string, error)

func StrToUint16

func StrToUint16(str string) (uint16, error)

func StrToUint32

func StrToUint32(str string) (uint32, error)

func StrToUint8

func StrToUint8(str string) (uint8, error)

Types

type AsciiBox

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

AsciiBox is a string surrounded by an ascii border (and an optional name)

func BoxAnything

func BoxAnything(name string, anything any, charWidth int) AsciiBox

func BoxedDump

func BoxedDump(name string, data []byte) AsciiBox

BoxedDump dumps a 56+2 char wide hex string

func BoxedDumpAnything

func BoxedDumpAnything(name string, anything any) AsciiBox

BoxedDumpAnything dumps anything as hex into a beautiful box

func BoxedDumpAnythingFixedWidth

func BoxedDumpAnythingFixedWidth(name string, anything any, charWidth int) AsciiBox

BoxedDumpAnythingFixedWidth dumps anything as hex into a beautiful box with a given width

func BoxedDumpFixedWidth

func BoxedDumpFixedWidth(name string, data []byte, charWidth int) AsciiBox

BoxedDumpFixedWidth dumps a hex into a beautiful box

func DiffHex

func DiffHex(expectedBytes, actualBytes []byte) AsciiBox

DiffHex produces a hex diff AsciiBox of two byte arrays

func (AsciiBox) ChangeBoxName

func (m AsciiBox) ChangeBoxName(newName string) AsciiBox

func (AsciiBox) GetBoxName

func (m AsciiBox) GetBoxName() string

func (AsciiBox) Height

func (m AsciiBox) Height() int

Height returns the height of the box without

func (AsciiBox) IsEmpty

func (m AsciiBox) IsEmpty() bool

func (AsciiBox) Lines

func (m AsciiBox) Lines() []string

Lines returns the lines of the box

func (AsciiBox) String

func (m AsciiBox) String() string

String returns the string of the box

func (AsciiBox) Width

func (m AsciiBox) Width() int

Width returns the width of the box without the newlines

type AsciiBoxWriter

type AsciiBoxWriter interface {
	BoxBox(name string, box AsciiBox, charWidth int) AsciiBox
	BoxString(name string, data string, charWidth int) AsciiBox
	AlignBoxes(asciiBoxes []AsciiBox, desiredWith int) AsciiBox
	BoxSideBySide(box1 AsciiBox, box2 AsciiBox) AsciiBox
	BoxBelowBox(box1 AsciiBox, box2 AsciiBox) AsciiBox
}

func NewAsciiBoxWriter

func NewAsciiBoxWriter() AsciiBoxWriter

func NewAsciiBoxWriterWithCustomBorders

func NewAsciiBoxWriterWithCustomBorders(upperLeftCorner string, upperRightCorner string, horizontalLine string, verticalLine string, lowerLeftCorner string, lowerRightCorner string) AsciiBoxWriter

type AsciiBoxer

type AsciiBoxer interface {
	// Box where int param is the proposed width
	Box(string, int) AsciiBox
}

AsciiBoxer is used to render something in a box

type BufferCommons

type BufferCommons struct {
}

func (BufferCommons) ExtractAdditionalStringRepresentation

func (b BufferCommons) ExtractAdditionalStringRepresentation(readerWriterArgs ...WithReaderWriterArgs) string

func (BufferCommons) ExtractEncoding

func (b BufferCommons) ExtractEncoding(readerWriterArgs ...WithReaderWriterArgs) string

func (BufferCommons) IsToBeRenderedAsList

func (b BufferCommons) IsToBeRenderedAsList(readerWriterArgs ...WithReaderWriterArgs) bool

func (BufferCommons) SanitizeLogicalName

func (b BufferCommons) SanitizeLogicalName(logicalName string) string

type ErrorIdentify

type ErrorIdentify interface {
	Is(target error) bool
}

ErrorIdentify is an interface defining the inline interface defined in errors.Is(err, target error) bool (wrap.go)

type LengthAware

type LengthAware interface {
	// GetLengthInBytes returns the length in bytes
	GetLengthInBytes(ctx context.Context) uint16
	// GetLengthInBits returns the length in bits
	GetLengthInBits(ctx context.Context) uint16
}

type MultiError

type MultiError struct {
	// MainError denotes the error which summarize the error
	MainError error
	// Errors are the child errors
	Errors []error
}

MultiError is a Wrapper for multiple Errors

func (MultiError) Error

func (m MultiError) Error() string

func (MultiError) Is

func (m MultiError) Is(target error) bool

type ParseAssertError

type ParseAssertError struct {
	Message string
}

func (ParseAssertError) Error

func (e ParseAssertError) Error() string

func (ParseAssertError) Is

func (e ParseAssertError) Is(target error) bool

type ParseValidationError

type ParseValidationError struct {
	Message string
}

func (ParseValidationError) Error

func (e ParseValidationError) Error() string

func (ParseValidationError) Is

func (e ParseValidationError) Is(target error) bool

type PlcValue deprecated

type PlcValue interface {
	apiValues.PlcValue
}

Deprecated: don't use it in productive code

type PositionAware

type PositionAware interface {
	// GetPos return the current byte position
	GetPos() uint16
}

type ReadBuffer

type ReadBuffer interface {
	PositionAware
	// Reset sets the position to the supplied byte position
	Reset(pos uint16)
	// HasMore returns true if there are bitLength bits available
	HasMore(bitLength uint8) bool
	// PullContext signals that we expect now a context with the supplied logical name
	PullContext(logicalName string, readerArgs ...WithReaderArgs) error
	ReadBit(logicalName string, readerArgs ...WithReaderArgs) (bool, error)
	ReadByte(logicalName string, readerArgs ...WithReaderArgs) (byte, error)
	ReadByteArray(logicalName string, numberOfBytes int, readerArgs ...WithReaderArgs) ([]byte, error)
	ReadUint8(logicalName string, bitLength uint8, readerArgs ...WithReaderArgs) (uint8, error)
	ReadUint16(logicalName string, bitLength uint8, readerArgs ...WithReaderArgs) (uint16, error)
	ReadUint32(logicalName string, bitLength uint8, readerArgs ...WithReaderArgs) (uint32, error)
	ReadUint64(logicalName string, bitLength uint8, readerArgs ...WithReaderArgs) (uint64, error)
	ReadInt8(logicalName string, bitLength uint8, readerArgs ...WithReaderArgs) (int8, error)
	ReadInt16(logicalName string, bitLength uint8, readerArgs ...WithReaderArgs) (int16, error)
	ReadInt32(logicalName string, bitLength uint8, readerArgs ...WithReaderArgs) (int32, error)
	ReadInt64(logicalName string, bitLength uint8, readerArgs ...WithReaderArgs) (int64, error)
	ReadBigInt(logicalName string, bitLength uint64, readerArgs ...WithReaderArgs) (*big.Int, error)
	ReadFloat32(logicalName string, bitLength uint8, readerArgs ...WithReaderArgs) (float32, error)
	ReadFloat64(logicalName string, bitLength uint8, readerArgs ...WithReaderArgs) (float64, error)
	ReadBigFloat(logicalName string, bitLength uint8, readerArgs ...WithReaderArgs) (*big.Float, error)
	ReadString(logicalName string, bitLength uint32, encoding string, readerArgs ...WithReaderArgs) (string, error)
	// CloseContext signals that we expect the end of the context with the supplied logical name
	CloseContext(logicalName string, readerArgs ...WithReaderArgs) error
}

func NewJsonReadBuffer

func NewJsonReadBuffer(reader io.Reader) ReadBuffer

NewJsonReadBuffer return as ReadBuffer which doesn't validate attributes and lists

func NewStrictJsonReadBuffer

func NewStrictJsonReadBuffer(reader io.Reader, validateAttr bool) ReadBuffer

NewStrictJsonReadBuffer return as ReadBuffer which does validate attributes on the setting

func NewStrictXmlReadBuffer

func NewStrictXmlReadBuffer(reader io.Reader, validateAttr bool, validateList bool) ReadBuffer

NewStrictXmlReadBuffer return as ReadBuffer which does validate attributes and lists depending on the setting

func NewXmlReadBuffer

func NewXmlReadBuffer(reader io.Reader) ReadBuffer

NewXmlReadBuffer return as ReadBuffer which doesn't validate attributes and lists

type ReadBufferByteBased

type ReadBufferByteBased interface {
	ReadBuffer
	GetBytes() []byte
	GetTotalBytes() uint64
	PeekByte(offset byte) byte
}

func NewReadBufferByteBased

func NewReadBufferByteBased(data []byte, options ...ReadBufferByteBasedOptions) ReadBufferByteBased

type ReadBufferByteBasedOptions

type ReadBufferByteBasedOptions = func(b *byteReadBuffer)

func WithByteOrderForReadBufferByteBased

func WithByteOrderForReadBufferByteBased(byteOrder binary.ByteOrder) ReadBufferByteBasedOptions

type Serializable

type Serializable interface {
	// Serialize serializes this type
	Serialize() ([]byte, error)
	// SerializeWithWriteBuffer serializes this type with a custom buffer
	SerializeWithWriteBuffer(ctx context.Context, writeBuffer WriteBuffer) error
}

type Stack

type Stack struct {
	list.List
}

func (*Stack) Empty

func (s *Stack) Empty() bool

func (*Stack) Peek

func (s *Stack) Peek() any

func (*Stack) Pop

func (s *Stack) Pop() any

func (*Stack) Push

func (s *Stack) Push(value any) any

type TimeoutError

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

func NewTimeoutError

func NewTimeoutError(timeout time.Duration) TimeoutError

func (TimeoutError) Error

func (t TimeoutError) Error() string

func (TimeoutError) Is

func (t TimeoutError) Is(target error) bool

type WithReaderArgs

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

WithReaderArgs is a marker interface for reader args supplied by the builders

type WithReaderWriterArgs

type WithReaderWriterArgs interface {
	WithReaderArgs
	WithWriterArgs
}

WithReaderWriterArgs is a marker interface for reader args supplied by the builders

func UpcastReaderArgs

func UpcastReaderArgs(args ...WithReaderArgs) []WithReaderWriterArgs

func UpcastWriterArgs

func UpcastWriterArgs(args ...WithWriterArgs) []WithReaderWriterArgs

func WithAdditionalStringRepresentation

func WithAdditionalStringRepresentation(stringRepresentation string) WithReaderWriterArgs

WithAdditionalStringRepresentation can be used by e.g. enums to supply an additional string representation

func WithEncoding

func WithEncoding(encoding string) WithReaderWriterArgs

WithEncoding specifies an encoding

func WithRenderAsList

func WithRenderAsList(renderAsList bool) WithReaderWriterArgs

WithRenderAsList indicates that an element can be rendered as list

type WithWriterArgs

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

WithWriterArgs is a marker interface for writer args supplied by the builders like WithAdditionalStringRepresentation

type WriteBuffer

type WriteBuffer interface {
	PositionAware
	// PushContext signals opening context with the supplied logical name
	PushContext(logicalName string, writerArgs ...WithWriterArgs) error
	WriteBit(logicalName string, value bool, writerArgs ...WithWriterArgs) error
	WriteByte(logicalName string, value byte, writerArgs ...WithWriterArgs) error
	WriteByteArray(logicalName string, data []byte, writerArgs ...WithWriterArgs) error
	WriteUint8(logicalName string, bitLength uint8, value uint8, writerArgs ...WithWriterArgs) error
	WriteUint16(logicalName string, bitLength uint8, value uint16, writerArgs ...WithWriterArgs) error
	WriteUint32(logicalName string, bitLength uint8, value uint32, writerArgs ...WithWriterArgs) error
	WriteUint64(logicalName string, bitLength uint8, value uint64, writerArgs ...WithWriterArgs) error
	WriteInt8(logicalName string, bitLength uint8, value int8, writerArgs ...WithWriterArgs) error
	WriteInt16(logicalName string, bitLength uint8, value int16, writerArgs ...WithWriterArgs) error
	WriteInt32(logicalName string, bitLength uint8, value int32, writerArgs ...WithWriterArgs) error
	WriteInt64(logicalName string, bitLength uint8, value int64, writerArgs ...WithWriterArgs) error
	WriteBigInt(logicalName string, bitLength uint8, value *big.Int, writerArgs ...WithWriterArgs) error
	WriteFloat32(logicalName string, bitLength uint8, value float32, writerArgs ...WithWriterArgs) error
	WriteFloat64(logicalName string, bitLength uint8, value float64, writerArgs ...WithWriterArgs) error
	WriteBigFloat(logicalName string, bitLength uint8, value *big.Float, writerArgs ...WithWriterArgs) error
	WriteString(logicalName string, bitLength uint32, encoding string, value string, writerArgs ...WithWriterArgs) error
	WriteVirtual(ctx context.Context, logicalName string, value any, writerArgs ...WithWriterArgs) error
	WriteSerializable(ctx context.Context, serializable Serializable) error
	// PopContext signals work done with the context with the supplied logical name
	PopContext(logicalName string, writerArgs ...WithWriterArgs) error
}

type WriteBufferBoxBased

type WriteBufferBoxBased interface {
	WriteBuffer
	GetBox() AsciiBox
}

func NewWriteBufferBoxBased

func NewWriteBufferBoxBased() WriteBufferBoxBased

func NewWriteBufferBoxBasedWithOptions

func NewWriteBufferBoxBasedWithOptions(mergeSingleBoxes bool, omitEmptyBoxes bool) WriteBufferBoxBased

type WriteBufferByteBased

type WriteBufferByteBased interface {
	WriteBuffer
	GetPos() uint16
	GetBytes() []byte
	GetTotalBytes() uint64
}

func NewWriteBufferByteBased

func NewWriteBufferByteBased(options ...WriteBufferByteBasedOptions) WriteBufferByteBased

type WriteBufferByteBasedOptions

type WriteBufferByteBasedOptions = func(b *byteWriteBuffer)

func WithByteOrderForByteBasedBuffer

func WithByteOrderForByteBasedBuffer(byteOrder binary.ByteOrder) WriteBufferByteBasedOptions

func WithCustomBufferForByteBasedBuffer

func WithCustomBufferForByteBasedBuffer(buffer *bytes.Buffer) WriteBufferByteBasedOptions

func WithInitialSizeForByteBasedBuffer

func WithInitialSizeForByteBasedBuffer(length int) WriteBufferByteBasedOptions

type WriteBufferJsonBased

type WriteBufferJsonBased interface {
	WriteBuffer
	GetJsonString() (string, error)
}

func NewJsonWriteBuffer

func NewJsonWriteBuffer() WriteBufferJsonBased

func NewJsonWriteBufferWithOptions

func NewJsonWriteBufferWithOptions(renderAttr bool) WriteBufferJsonBased

type WriteBufferXmlBased

type WriteBufferXmlBased interface {
	WriteBuffer
	GetXmlString() string
}

func NewConfiguredXmlWriteBuffer

func NewConfiguredXmlWriteBuffer(renderLists bool, renderAttr bool) WriteBufferXmlBased

NewConfiguredXmlWriteBuffer returns a WriteBufferXmlBased which renders configured information into xml

func NewXmlWriteBuffer

func NewXmlWriteBuffer() WriteBufferXmlBased

NewXmlWriteBuffer returns a WriteBufferXmlBased which renders all information into xml

Jump to

Keyboard shortcuts

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