wire

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT, MIT Imports: 13 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 encodes and decodes Wayland protocol messages on a Unix socket.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidOpcode  = errors.New("invalid opcode")
	ErrVersion        = errors.New("not supported by the bound version")
	ErrUnknownObject  = errors.New("unknown object")
	ErrWrongInterface = errors.New("object has the wrong interface")
	ErrNullObject     = errors.New("null object for a non-nullable argument")
	ErrInvalidNewID   = errors.New("invalid new object id")
	ErrNoHandler      = errors.New("no handler for a new object")
)
View Source
var (
	ErrTruncated          = errors.New("argument runs past the end of the message")
	ErrNullString         = errors.New("null string for a non-nullable argument")
	ErrUnterminatedString = errors.New("string is not NUL-terminated")
	ErrEmbeddedNUL        = errors.New("string contains a NUL byte")
	ErrMissingFD          = errors.New("file descriptor expected but none received")
	ErrTrailingBytes      = errors.New("bytes left after the last argument")
	ErrMessageSize        = errors.New("invalid message size")
	ErrMessageTooLarge    = errors.New("message exceeds the maximum size")
	ErrTooManyFDs         = errors.New("too many file descriptors")
	ErrOutputFull         = errors.New("output buffer full: the peer is not reading")
	ErrWouldBlock         = errors.New("socket buffer full")
)
View Source
var ErrOutOfRange = errors.New("wire: the value does not fit the protocol")

Functions

func AppendArgs

func AppendArgs(dst []byte, args []Arg, body []byte) []byte

func ArgWalk

func ArgWalk(data []byte, args []Arg, f func(a Arg, off int)) error

func CheckVersion

func CheckVersion(iface *Interface, version uint32) error

func CloseUnclaimed

func CloseUnclaimed(err error, fds ...int) error

func Halves

func Halves(v uint64) (hi, lo uint32)

func Int32

func Int32(v int) (int32, error)

func Join

func Join(hi, lo uint32) uint64

func Millis

func Millis(t time.Duration) uint32

func NoHandler

func NoHandler(iface *Interface) error

func ObjectArg

func ObjectArg[T Resource](m *Message, p Peer, nullable bool) T

func Point

func Point(p image.Point) (x, y int32, err error)

func SetObjectAt

func SetObjectAt(data []byte, off int, id ObjectID)

func Size

func Size(p image.Point) (w, h int32, err error)

func StringAt

func StringAt(data []byte, off int) string

func Uint32

func Uint32(v int) (uint32, error)

Types

type Arg

type Arg struct {
	Name      string
	Type      ArgType
	Interface string
	Nullable  bool
}

type ArgType

type ArgType uint8
const (
	ArgInt ArgType = iota + 1
	ArgUint
	ArgFixed
	ArgString
	ArgObject
	ArgNewID
	ArgArray
	ArgFD
)

type Conn

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

func NewConn

func NewConn(fd int) *Conn

func NewRecorder

func NewRecorder() *Conn

func (*Conn) Begin

func (c *Conn) Begin(object ObjectID, opcode Opcode) *Encoder

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) DeferSendErrors

func (c *Conn) DeferSendErrors()

func (*Conn) Err

func (c *Conn) Err() error

func (*Conn) FD

func (c *Conn) FD() int

func (*Conn) Feed

func (c *Conn) Feed(in []byte, fds []int) error

func (*Conn) Fill

func (c *Conn) Fill() error

func (*Conn) Flush

func (c *Conn) Flush() error

func (*Conn) Mute

func (c *Conn) Mute()

func (*Conn) Next

func (c *Conn) Next() (*Message, error)

func (*Conn) Pending

func (c *Conn) Pending() (in []byte, inFDs []int, out []byte, outFDs []int)

func (*Conn) Raw

func (c *Conn) Raw(data []byte, fds []int) error

func (*Conn) Recorded

func (c *Conn) Recorded() ([]byte, []int)

func (*Conn) SetTracer

func (c *Conn) SetTracer(t Tracer)

func (*Conn) Unmute

func (c *Conn) Unmute(keep func(id ObjectID, opcode Opcode) (bool, int), prefix []byte, prefixFDs []int) error

type Encoder

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

func (*Encoder) Array

func (e *Encoder) Array(b []byte)

func (*Encoder) End

func (e *Encoder) End() error

func (*Encoder) FD

func (e *Encoder) FD(fd int)

func (*Encoder) Fixed

func (e *Encoder) Fixed(v Fixed)

func (*Encoder) Int

func (e *Encoder) Int(v int32)

func (*Encoder) NullStr

func (e *Encoder) NullStr()

func (*Encoder) Object

func (e *Encoder) Object(id ObjectID)

func (*Encoder) Str

func (e *Encoder) Str(s string)

func (*Encoder) Uint

func (e *Encoder) Uint(v uint32)

type Fixed

type Fixed int32

func FixedFromFloat

func FixedFromFloat(f float64) Fixed

func (Fixed) Float

func (f Fixed) Float() float64

type Interface

type Interface struct {
	Name     string
	Version  uint32
	Requests []MessageSpec
	Events   []MessageSpec
}

type Message

type Message struct {
	ID     ObjectID
	Opcode Opcode
	// contains filtered or unexported fields
}

func (*Message) Array

func (m *Message) Array() []byte

func (*Message) FD

func (m *Message) FD() int

func (*Message) Finish

func (m *Message) Finish() error

func (*Message) Fixed

func (m *Message) Fixed() Fixed

func (*Message) Int

func (m *Message) Int() int32

func (*Message) NewID

func (m *Message) NewID() ObjectID

func (*Message) Object

func (m *Message) Object() ObjectID

func (*Message) OptStr

func (m *Message) OptStr() (string, bool)

func (*Message) PeekFDs

func (m *Message) PeekFDs(n int) []int

func (*Message) Raw

func (m *Message) Raw() []byte

func (*Message) Skip

func (m *Message) Skip()

func (*Message) Str

func (m *Message) Str() string

func (*Message) Uint

func (m *Message) Uint() uint32

type MessageError

type MessageError struct {
	Object ObjectID
	Opcode Opcode
	Offset int
	Err    error
}

func (*MessageError) Error

func (e *MessageError) Error() string

func (*MessageError) Unwrap

func (e *MessageError) Unwrap() error

type MessageSpec

type MessageSpec struct {
	Name       string
	Since      uint32
	Destructor bool
	Args       []Arg
}

type Object

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

func NewObject

func NewObject(p Peer, id ObjectID, version uint32, iface *Interface) (Object, error)

func (*Object) Begin

func (o *Object) Begin(opcode Opcode) *Encoder

func (*Object) Expect

func (o *Object) Expect(m *Message, specs []MessageSpec) int

func (*Object) ID

func (o *Object) ID() ObjectID

func (*Object) Interface

func (o *Object) Interface() *Interface

func (*Object) MarkRemoved

func (o *Object) MarkRemoved()

func (*Object) NullArg

func (o *Object) NullArg(message, arg string) error

func (*Object) Owns

func (o *Object) Owns(r Resource) error

func (*Object) Peer

func (o *Object) Peer() Peer

func (*Object) Removed

func (o *Object) Removed() bool

func (*Object) Require

func (o *Object) Require(message string, since uint32) error

func (*Object) Version

func (o *Object) Version() uint32

type ObjectID

type ObjectID uint32
const (
	FirstServerID ObjectID = 0xff000000
	LastServerID  ObjectID = 0xffffffff
)

func ObjectAt

func ObjectAt(data []byte, off int) ObjectID

func (ObjectID) ServerSide

func (id ObjectID) ServerSide() bool

type Opcode

type Opcode uint16

type Peer

type Peer interface {
	Conn() *Conn
	Get(id ObjectID) (Resource, bool)
	Add(r Resource) error
	Remove(id ObjectID) error
	NewID() (ObjectID, error)
}

type ProtocolError

type ProtocolError struct {
	Object  ObjectID
	Code    uint32
	Message string
}

func NewProtocolError

func NewProtocolError(object ObjectID, code uint32, format string, args ...any) *ProtocolError

func (*ProtocolError) Error

func (e *ProtocolError) Error() string

type Resource

type Resource interface {
	Base() *Object
	Dispatch(m *Message) error
}

type Timespec

type Timespec struct{ SecHi, SecLo, Nsec uint32 }

func TimespecOf

func TimespecOf(t time.Duration) Timespec

type Tracer

type Tracer func(incoming bool, id ObjectID, opcode Opcode, body []byte)

Jump to

Keyboard shortcuts

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