stream

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package stream provides streaming protocol decoding from io.Reader.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FrameConfig

type FrameConfig struct {
	Type         FrameType
	LengthBytes  int    // For LengthPrefixed: 1, 2, or 4
	LengthOffset int    // Offset to add to length value
	BigEndian    bool   // Byte order for length field
	Delimiter    []byte // For Delimited framing
	FixedSize    int    // For FixedLength framing
}

FrameConfig configures message framing.

type FrameType

type FrameType int

FrameType defines how message boundaries are detected.

const (
	LengthPrefixed FrameType = iota // Length field precedes payload
	Delimited                       // Delimiter separates messages
	FixedLength                     // All messages have the same length
)

type Message

type Message struct {
	Raw    []byte
	Fields map[string]any
	Err    error
}

Message holds a decoded message from the stream.

type StateMachine

type StateMachine struct {
	Current     string
	Transitions map[string]map[string]string // from -> trigger -> to
}

StateMachine tracks protocol state transitions.

func NewStateMachine

func NewStateMachine(initial string) *StateMachine

NewStateMachine creates a state machine with an initial state.

func (*StateMachine) AddTransition

func (sm *StateMachine) AddTransition(from, trigger, to string)

AddTransition adds a state transition rule.

func (*StateMachine) Trigger

func (sm *StateMachine) Trigger(event string) (string, error)

Trigger attempts a state transition and returns the new state.

type StreamDecoder

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

StreamDecoder reads and decodes protocol messages from a stream.

func NewStreamDecoder

func NewStreamDecoder(r io.Reader, lib *protocol.Library, proto string, frame FrameConfig) *StreamDecoder

NewStreamDecoder creates a new stream decoder.

func (*StreamDecoder) Next

func (sd *StreamDecoder) Next() (*Message, error)

Next reads and decodes the next message from the stream.

Jump to

Keyboard shortcuts

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