decoder

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package decoder provides several decoders for differently encoded trice streams.

Index

Constants

View Source
const (

	// LittleEndian is true for little endian trice data.
	LittleEndian = true

	// BigEndian is the flag value for target endianness.
	BigEndian = false

	// defaultSize is the beginning receive and sync buffer size.
	DefaultSize = 64 * 1024

	// hints is the help information in case of errors.
	Hints = "att:Hints:Baudrate? Encoding? Interrupt? Overflow? Parameter count? Format specifier? Password? til.json? Version?"

	UnsignedFormatSpecifier = 0 // %u -> %d
	SignedFormatSpecifier   = 1 // signed integer formatting
	FloatFormatSpecifier    = 2 // %f and relatives
	BooleanFormatSpecifier  = 3 // a %t (bool) found
	PointerFormatSpecifier  = 4 // a %p (pointer) found
	StringFormatSpecifier   = 5 // a %s found

	// LiFmtDefault is the default layout for location info (file and line).
	LiFmtDefault = "info:%21s%6d "
)

Variables

View Source
var (
	// Verbose gives more information on output if set. The value is injected from main packages.
	Verbose bool

	// ShowID is used as format string for displaying the first trice ID at the start of each line if not "".
	ShowID string

	// TypeX0 controls how selector-0 records are interpreted by decoders that support typeX0.
	TypeX0 = "error"

	// BlankMetadata requests metadata columns without their value content for the current decoded output.
	BlankMetadata bool

	// decoder.LastTriceID is last decoded ID. It is used for switch -showID.
	LastTriceID id.TriceID

	// TestTableMode is a special option for easy decoder test table generation.
	TestTableMode bool

	// Unsigned if true, forces hex and in values printed as unsigned values.
	Unsigned bool

	DebugOut                        = false        // DebugOut enables debug information.
	DumpLineByteCount               int            // DumpLineByteCount is the bytes per line for the dumpDec decoder.
	InitialCycle                    = true         // InitialCycle helps with automatic cycle counter checks.
	TargetTimestamp                 uint64         // targetTimestamp contains target specific timestamp value.
	TargetTimestampSize             int            // TargetTimestampSize is set in dependence of trice type.
	TargetLocation                  uint32         // targetLocation contains 16 bit file id in high and 16 bit line number in low part.
	TargetStamp                     string         // TargetTimeStampUnit is the target timestamps time base for default formatting.
	TargetStamp32                   string         // ShowTargetStamp32 is the format string for target timestamps.
	TargetStamp16                   string         // ShowTargetStamp16 is the format string for target timestamps.
	TargetStamp0                    string         // ShowTargetStamp0 is the format string for target timestamps.
	TargetStamp32Delta              string         // TargetStamp32Delta is the format string for 32-bit target timestamp deltas.
	TargetStamp16Delta              string         // TargetStamp16Delta is the format string for 16-bit target timestamp deltas.
	TargetStamp0Delta               string         // TargetStamp0Delta is the format string for delta column alignment without target timestamps.
	TargetTimeStampUnitPassed       bool           // TargetTimeStampUnitPassed is true when flag was TargetTimeStampUnit passed.
	ShowTargetStamp32Passed         bool           // ShowTargetStamp32Passed is true when flag was TargetTimeStamp32 passed.
	ShowTargetStamp16Passed         bool           // ShowTargetStamp16Passed is true when flag was TargetTimeStamp16 passed.
	ShowTargetStamp0Passed          bool           // ShowTargetStamp0Passed is true when flag was TargetTimeStamp0 passed.
	ShowTargetStamp32DeltaPassed    bool           // ShowTargetStamp32DeltaPassed is true when flag TargetStamp32Delta was passed.
	ShowTargetStamp16DeltaPassed    bool           // ShowTargetStamp16DeltaPassed is true when flag TargetStamp16Delta was passed.
	ShowTargetStamp0DeltaPassed     bool           // ShowTargetStamp0DeltaPassed is true when flag TargetStamp0Delta was passed.
	LocationInformationFormatString = LiFmtDefault // LocationInformationFormatString is the format string for target location: line number and file name.
	LiFmtDefaultLen                 int            // Compute as var from LocationInformationFormatString.
	TargetLocationExists            bool           // TargetLocationExists is set in dependence of p.COBSModeDescriptor. (obsolete)
	PackageFraming                  string         // Framing is used for packing. Valid values COBS, TCOBS, TCOBSv1 (same as TCOBS)
	IDBits                          = 14           // IDBits holds count of bits used for ID (used at least in trexDecoder)
	NewlineIndent                   = -1           // Used for trice messages containing several newlines in format string for formatting.
	TriceStatistics                 bool           // Keep the occurred count for each Trice log when Trice is closed.
	IDStat                          map[id.TriceID]int
)

Functions

func CorrectWrappedTimestamp added in v1.1.0

func CorrectWrappedTimestamp(ts32 uint32) time.Time

CorrectWrappedTimestamp checks whether a 32-bit timestamp falls outside the valid range and virtually sets a 33rd bit by adding 2^32 seconds to it

func Dump added in v0.55.1

func Dump(w io.Writer, b []byte)

Dump prints the byte slice as hex in one line

func LocationInformation added in v1.1.0

func LocationInformation(tid id.TriceID, li id.TriceIDLookUpLI) string

LocationInformation returns optional location information for id.

func PrintTriceStatistics added in v0.72.4

func PrintTriceStatistics(w io.Writer)

func RecordForStatistics added in v0.72.4

func RecordForStatistics(tid id.TriceID)

func Register added in v1.2.0

func Register(name string, ctor New)

Register associates an encoding name with a decoder constructor.

Names are matched case-insensitively.

func UReplaceN added in v0.55.1

func UReplaceN(i string) (o string, u []int)

UReplaceN checks all format specifier in i and replaces %nu with %nd and returns that result as o.

If a replacement took place on position k u[k] is 0. Afterwards len(u) is amount of found format specifiers. Additional, if UnsignedHex is true, for FormatX specifiers u[k] is also 1. If a float format specifier was found at position k, u[k] is 2, http://www.cplusplus.com/reference/cstdio/printf/ https://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output

Types

type Config added in v1.2.0

type Config struct {
	Out         io.Writer
	LUT         id.TriceIDLookUp
	LUTMutex    *sync.RWMutex
	LI          id.TriceIDLookUpLI
	In          io.Reader
	Endian      bool
	NeedBuffers bool // NeedBuffers allocates B, B0 and InnerBuffer for framed decoders.
}

Config contains common constructor parameters for all decoders.

type Decoder

type Decoder interface {
	io.Reader
	SetInput(io.Reader)
}

Decoder is providing a byte reader returning decoded trice's. SetInput allows switching the input stream to a different source.

func NewForEncoding added in v1.2.0

func NewForEncoding(encoding string, out io.Writer, lut id.TriceIDLookUp, m *sync.RWMutex, li id.TriceIDLookUpLI, in io.Reader, endian bool) (Decoder, error)

NewForEncoding creates a decoder instance for the requested encoding.

type DecoderData added in v0.55.1

type DecoderData struct {
	W           io.Writer          // io.Stdout or the like
	In          io.Reader          // in is the inner reader, which is used to get raw bytes
	InnerBuffer []byte             // avoid repeated allocation (trex)
	IBuf        []byte             // iBuf holds unprocessed (raw) bytes for interpretation.
	B           []byte             // read buffer holds a single decoded TCOBS package, which can contain several trices.
	B0          []byte             // initial value for B
	Endian      bool               // endian is true for LittleEndian and false for BigEndian
	TriceSize   int                // trice head and payload size as number of bytes
	ParamSpace  int                // trice payload size after head
	SLen        int                // string length for TRICE_S
	Lut         id.TriceIDLookUp   // id look-up map for translation
	LutMutex    *sync.RWMutex      // to avoid concurrent map read and map write during map refresh triggered by filewatcher
	Li          id.TriceIDLookUpLI // location information map
	Trice       id.TriceFmt        // id.TriceFmt // received trice
}

DecoderData is the common data struct for all decoders.

func NewDecoderData added in v1.2.0

func NewDecoderData(c Config) DecoderData

NewDecoderData initializes the common base fields for a decoder.

Callers can request pre-allocated internal working buffers with NeedBuffers.

func (*DecoderData) ReadU16 added in v0.55.1

func (p *DecoderData) ReadU16(b []byte) uint16

ReadU16 returns the 2 b bytes as uint16 according the specified endianness

func (*DecoderData) ReadU32 added in v0.55.1

func (p *DecoderData) ReadU32(b []byte) uint32

ReadU32 returns the 4 b bytes as uint32 according the specified endianness

func (*DecoderData) ReadU64 added in v0.55.1

func (p *DecoderData) ReadU64(b []byte) uint64

ReadU64 returns the 8 b bytes as uint64 according the specified endianness

func (*DecoderData) SetInput added in v0.55.1

func (p *DecoderData) SetInput(r io.Reader)

SetInput allows switching the input stream to a different source.

This function is for easier testing with cycle counters.

type New added in v0.55.1

type New func(out io.Writer, lut id.TriceIDLookUp, m *sync.RWMutex, li id.TriceIDLookUpLI, in io.Reader, endian bool) Decoder

New abstracts the function type for a new decoder.

type TestTable added in v0.55.1

type TestTable []struct {
	In  []byte // byte buffer sequence
	Exp string // output
}

TestTable is a struct slice generated by the trice tool -testTable option.

type TypeX0Result added in v1.2.4

type TypeX0Result struct {
	Text          string // Text is the optional host output generated for this X0 record.
	Consumed      int    // Consumed is the byte count to remove from the current decoded record buffer.
	BlankMetadata bool   // BlankMetadata requests aligned, value-less metadata for Text.
}

TypeX0Result describes how a decoder shall continue after a selector-0 record.

func HandleTypeX0 added in v1.2.4

func HandleTypeX0(record []byte, endian bool, noneFraming bool) TypeX0Result

HandleTypeX0 interprets one selector-0 record at the start of record.

Jump to

Keyboard shortcuts

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