wire

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package wire is the protocol between the host and the on-device agents.

One TCP connection carries everything in both directions. Each message is a single line of JSON. A message may carry binary data (a screenshot): it then has a "bin" field with the byte count, and that many raw bytes follow the newline.

The host sends requests: {"id":7,"op":"tap","x":100,"y":200} The agent answers each: {"id":7,"ok":true,...} or {"id":7,"ok":false,"error":"..."} The agent also pushes events without being asked (no "id"):

{"ev":"changed","seq":41}   the UI changed (an accessibility event arrived)
{"ev":"settled","seq":41}   no change for the quiet window since seq 41

The host never polls: it waits on these events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentError

type AgentError struct {
	Op        string
	Msg       string
	Transient bool
}

AgentError is an error the agent reported for a request. Transient is the reply's "transient": the agent says asking again may succeed.

func (*AgentError) Error

func (e *AgentError) Error() string

type Conn

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

Conn is a connection to one agent.

func Dial

func Dial(addr string, timeout time.Duration) (*Conn, error)

Dial connects to an agent at addr, retrying until timeout while it starts up.

func (*Conn) Abandoned added in v0.5.3

func (c *Conn) Abandoned() int

Abandoned is how many requests given up on (CallContext) the device may still be running: a request sent now waits behind them.

func (*Conn) Call

func (c *Conn) Call(op string, params map[string]any, timeout time.Duration) (*Msg, error)

Call sends a request and waits for its answer. params is merged into the request.

func (*Conn) CallContext added in v0.5.3

func (c *Conn) CallContext(ctx context.Context, op string, params map[string]any, timeout time.Duration) (*Msg, error)

CallContext is Call that also ends with ctx (issue #202):

  • a ctx already done when CallContext is called sends nothing and returns ctx.Err() (context.Canceled, or context.DeadlineExceeded for a deadline already past);
  • a wait for the answer that ctx ends returns ctx.Err() when ctx was cancelled, and a *ReplyTimeout when its deadline passed, as a wait cut to the time left did before: callers tell a late answer by its type;
  • an answer that has arrived when ctx ends (or the timeout passes) is returned as the answer: what the agent did is reported done.

The connection stays usable after a call ctx ended. Answers are matched to requests by id, not by order: the call's id leaves pending when it gives up, so the agent's late answer to it finds no caller and is dropped (dispatch), and the next call waits for its own id.

The agents run requests one at a time, in order (Android: one reader thread; iOS: a serial queue), so a request sent after one that was given up on waits on the device until that one is done. The given-up request is remembered with the time it was bounded by (sent + its timeout): a later call's reply timeout starts once the answers to the given-up requests sent before it have arrived, or their bounds have passed, so it is not charged for the time they still take. ctx's own deadline is not moved.

func (*Conn) CallUnqueued added in v0.5.3

func (c *Conn) CallUnqueued(ctx context.Context, op string, params map[string]any, timeout time.Duration) (*Msg, error)

CallUnqueued is CallContext whose reply timeout starts at once, even with given-up requests still ahead of it on the device. For requests whose answer only says they arrived, sent on the way out (exit, keep): a timeout is better there than waiting, request after request, for every given-up one's bound (issue #202). The request still runs on the device once the ones ahead of it are done.

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Done

func (c *Conn) Done() <-chan struct{}

Done is closed when the connection drops.

func (*Conn) Err

func (c *Conn) Err() error

Err is why the connection dropped.

func (*Conn) Hello

func (c *Conn) Hello() *Msg

Hello is the agent's greeting.

func (*Conn) HelloVersion

func (c *Conn) HelloVersion() string

HelloVersion is the agent build version from its greeting.

func (*Conn) Seq

func (c *Conn) Seq() int64

Seq is the sequence number of the latest UI change the agent reported.

func (*Conn) SettledSeq

func (c *Conn) SettledSeq() int64

SettledSeq is the change sequence number the latest "settled" event covered.

func (*Conn) Subscribe

func (c *Conn) Subscribe() chan *Msg

Subscribe returns a channel of pushed events. Call Unsubscribe when done.

func (*Conn) Unsubscribe

func (c *Conn) Unsubscribe(ch chan *Msg)

type Msg

type Msg struct {
	ID    int64  `json:"id,omitempty"`
	OK    bool   `json:"ok,omitempty"`
	Error string `json:"error,omitempty"`
	// Transient marks an error the agent says is the device's passing state, not the
	// request's own failure: the host may ask again (iOS launch, issue #126).
	Transient bool            `json:"transient,omitempty"`
	Ev        string          `json:"ev,omitempty"`
	Seq       int64           `json:"seq,omitempty"`
	Bin       int             `json:"bin,omitempty"`
	Raw       json.RawMessage `json:"-"`
	Data      []byte          `json:"-"`
}

Msg is a decoded message. Raw keeps the full JSON so callers can decode op-specific fields.

func (*Msg) Decode

func (m *Msg) Decode(v any) error

Decode unmarshals the full message into v.

type ReplyTimeout added in v0.5.0

type ReplyTimeout struct {
	Op     string
	After  time.Duration
	Queued bool
}

ReplyTimeout means the request was sent but the agent's answer did not arrive. Queued: ctx's deadline ended it while it waited, at least in part, behind requests given up on (CallContext).

func (*ReplyTimeout) Error added in v0.5.0

func (e *ReplyTimeout) Error() string

Jump to

Keyboard shortcuts

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