protocol

package
v0.260507.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package protocol is the pure stream-protocol layer of agentboot. It has no knowledge of how the agent process is started or how its events are routed — it only understands bytes flowing in and out of an io.Reader/io.Writer.

This isolation makes the decoder testable against fixed JSON inputs without any process or goroutine plumbing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

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

Decoder reads a stream of JSON-encoded values from an io.Reader and emits them as Events on the channel returned by Stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder constructs a Decoder reading from r.

func (*Decoder) Stream

func (d *Decoder) Stream(ctx context.Context) (events <-chan Event, errFn func() error)

Stream consumes the decoder's input on a goroutine and returns the event channel together with an Err accessor.

Channel-close semantics:

  • The channel is closed exactly once, when the source reaches EOF, ctx is canceled, or a non-recoverable decode error occurs.
  • Err must only be called after the channel has been observed closed. The Go memory model guarantees the terminal error is visible to readers after channel-close synchronization.
  • If the source implements io.Closer, it is closed on ctx cancel so that an in-flight blocking Decode unblocks promptly. Callers that pass a non-closer reader must close it themselves to abort decoding.

If decoding succeeds and the source ends cleanly with EOF, Err returns nil.

type Encoder

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

Encoder writes control responses (and other outbound messages) as newline-delimited JSON to a destination io.Writer. It is safe for concurrent use; concurrent Encode calls are serialized so that no two JSON values interleave on the wire.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder constructs an Encoder targeting w.

func (*Encoder) Encode

func (e *Encoder) Encode(v any) error

Encode marshals v to JSON and writes it to the destination, terminated by a newline.

type Event

type Event = common.Event

Event is the type emitted by Decoder. It aliases common.Event so callers can pass values to the rest of agentboot without conversion.

Jump to

Keyboard shortcuts

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