Documentation
¶
Overview ¶
Package decoder provides decoding of defmt log frames produced by resource-constrained devices.
Index ¶
- Variables
- type Arg
- type ArgKind
- type BitflagsKey
- type BitflagsValue
- type DisplayHint
- type DisplayHintKind
- type Encoding
- type FormatSliceElement
- type Fragment
- type Frame
- type Level
- type ParamType
- type Parameter
- type StreamDecoder
- type StringEntry
- type Table
- type TableEntry
- type Tag
- type TimePrecision
- type TypeKind
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnexpectedEOF = errors.New("unexpected end of stream") ErrMalformed = errors.New("malformed data") )
Sentinel errors returned by Decode and StreamDecoder.
var DEFMT_VERSIONS = []string{"3", "4"}
DEFMT_VERSIONS lists the supported defmt wire format versions.
Functions ¶
This section is empty.
Types ¶
type Arg ¶
type Arg struct {
Kind ArgKind
Bool bool
F32 float32
F64 float64
// For ArgKindUxx: non-negative big.Int; for ArgKindIxx: signed big.Int
BigInt *big.Int
// For ArgKindStr, ArgKindIStr, ArgKindPreformatted
Str string
// For ArgKindFormat and ArgKindFormatSequence
Format string
Args []Arg
// For ArgKindFormatSlice
Elements []FormatSliceElement
// For ArgKindSlice
Slice []byte
// For ArgKindChar
Char rune
}
Arg is a decoded argument from a defmt frame.
type ArgKind ¶
type ArgKind int
ArgKind identifies which union arm of Arg is active.
const ( ArgKindBool ArgKind = iota ArgKindF32 ArgKindF64 ArgKindUxx // unsigned integer (up to u128) ArgKindIxx // signed integer (up to i128) ArgKindStr // dynamic string ArgKindIStr // interned string ArgKindFormat // nested formatted value ArgKindFormatSlice // slice of formatted values ArgKindFormatSequence // sequence of formats ArgKindSlice // []byte ArgKindChar // rune ArgKindPreformatted // pre-formatted string )
type BitflagsKey ¶
BitflagsKey uniquely identifies a defmt::bitflags! invocation.
type BitflagsValue ¶
type BitflagsValue struct {
Name string
Value uint64 // stored as uint64; actual type is u128 in Rust
}
BitflagsValue is a named bitflag with its value.
type DisplayHint ¶
type DisplayHint struct {
Kind DisplayHintKind
Alternate bool
Uppercase bool
ZeroPad int
Precision TimePrecision
Name string // for Bitflags
Package string // for Bitflags
Disambiguator string // for Bitflags
CrateName *string
UnknownStr string // for Unknown kind
}
DisplayHint describes how a value should be displayed.
type DisplayHintKind ¶
type DisplayHintKind int
DisplayHintKind is the kind of display hint.
const ( DisplayHintKindNone DisplayHintKind = iota DisplayHintKindHexadecimal // :x or :X DisplayHintKindOctal // :o DisplayHintKindBinary // :b DisplayHintKindAscii // :a DisplayHintKindDebug // :? DisplayHintKindSeconds // :us or :ms DisplayHintKindTime // :tus, :tms, :ts DisplayHintKindISO8601 // :iso8601ms or :iso8601s DisplayHintKindBitflags // __internal_bitflags_... DisplayHintKindCbor // :cbor DisplayHintKindUnknown )
type Encoding ¶
type Encoding int
Encoding describes how defmt frames are encoded.
func (Encoding) CanRecover ¶
CanRecover reports whether the encoding can recover from missed bytes.
type FormatSliceElement ¶
FormatSliceElement is one element in a FormatSlice arg.
type Fragment ¶
type Fragment struct {
IsLiteral bool
Literal string // valid when IsLiteral
Param Parameter // valid when !IsLiteral
}
Fragment is a part of a format string: either a literal string or a parameter.
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame is a decoded defmt log frame.
func (*Frame) Display ¶
Display returns the fully formatted log line including timestamp and level. When colored is true, ANSI color codes are used for the level.
func (*Frame) DisplayMessage ¶
DisplayMessage returns only the formatted message (no timestamp or level).
func (*Frame) DisplayTimestamp ¶
DisplayTimestamp returns the formatted timestamp, or empty string if none.
func (*Frame) Level ¶
Level returns the log level, or nil if the frame has no level (e.g. println!).
func (*Frame) TimestampArgs ¶
TimestampArgs returns the decoded arguments for the timestamp format string. Returns nil if the frame has no timestamp.
type ParamType ¶
type ParamType struct {
Kind TypeKind
BitStart uint8 // for BitField: start bit (inclusive)
BitEnd uint8 // for BitField: end bit (exclusive)
ArrayLen int // for FormatArray and U8Array
}
ParamType represents the type of a format parameter.
type Parameter ¶
type Parameter struct {
Index int
Type ParamType
Hint *DisplayHint // nil if no hint
}
Parameter is a parsed format parameter.
type StreamDecoder ¶
type StreamDecoder interface {
// Received feeds new data into the decoder's buffer.
Received(data []byte)
// Decode attempts to decode one frame from the buffered data.
// Returns ErrUnexpectedEOF if more data is needed, or ErrMalformed on error.
Decode() (*Frame, error)
}
StreamDecoder buffers incoming binary data and decodes defmt frames.
type StringEntry ¶
StringEntry holds a tag and format string.
type Table ¶
type Table struct {
Timestamp *TableEntry
Bitflags map[BitflagsKey][]BitflagsValue
// contains filtered or unexported fields
}
Table holds the decoded defmt metadata from an ELF file.
func ParseELF ¶
ParseELF parses an ELF binary and extracts the defmt Table. Returns nil with no error if the ELF does not use defmt.
func ParseELFIgnoreVersion ¶
ParseELFIgnoreVersion is like ParseELF but skips the defmt version check.
func (*Table) Decode ¶
Decode decodes one defmt frame from data and returns the frame plus the number of bytes consumed.
func (*Table) HasTimestamp ¶
HasTimestamp reports whether the table has a timestamp format.
func (*Table) Indices ¶
Indices returns all indices that correspond to log-level or println entries.
func (*Table) NewStreamDecoder ¶
func (t *Table) NewStreamDecoder() StreamDecoder
NewStreamDecoder creates a StreamDecoder appropriate for this table's encoding.
type TableEntry ¶
type TableEntry struct {
StringEntry StringEntry
RawSymbol string
}
TableEntry combines a format string with its raw ELF symbol.
type TimePrecision ¶
type TimePrecision int
TimePrecision is the precision of a time display hint.
const ( TimePrecisionMicros TimePrecision = iota TimePrecisionMillis TimePrecisionSeconds )
type TypeKind ¶
type TypeKind int
TypeKind represents the kind of a defmt parameter type.
const ( TypeKindFormat TypeKind = iota // {=?} or {} TypeKindBool // {=bool} TypeKindChar // {=char} TypeKindDebug // {=__internal_Debug} TypeKindDisplay // {=__internal_Display} TypeKindFormatSequence // {=__internal_FormatSequence} TypeKindF32 // {=f32} TypeKindF64 // {=f64} TypeKindFormatArray // {=[?; N]} TypeKindFormatSlice // {=[?]} TypeKindI8 TypeKindI16 TypeKindI32 TypeKindI64 TypeKindI128 TypeKindIsize TypeKindIStr // {=istr} TypeKindStr // {=str} TypeKindU8 TypeKindU16 TypeKindU32 TypeKindU64 TypeKindU128 TypeKindUsize TypeKindU8Slice // {=[u8]} TypeKindU8Array // {=[u8; N]} TypeKindBitField )