sidecar

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 26 Imported by: 1 module, 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 sidecar defines the process boundary between the engine and a model that is not written in Go.

Many audio-model inference stacks live in Python. Letting that Python into the build, the test path, or the analysis path would make every one of them slower and more fragile, so it stays on the other side of a process boundary with a documented, versioned protocol between. The conformance suite is the contract: a sidecar that passes it works, whatever it is written in, and a sidecar that does not is broken before anyone runs a model.

Framing

Each message is one JSON header line terminated by a newline, optionally followed by exactly PayloadBytes of binary payload:

{"type":"audio","payload_bytes":960}\n<960 bytes of PCM16>

Legacy audio/image frames and protocol-v4 typed element frames may use the binary lane. In v4, the selected port's explicit WireFormat—not its name or an audio-specific message kind—governs JSON/binary lanes and byte bounds. Headers remain ordinary JSON so the boundary can still be inspected without interpreting provider payloads.

Index

Constants

View Source
const (
	MaxElementPorts           = 256
	MaxPortWireFormats        = 16
	MaxElementCapabilities    = 512
	MaxElementRequirements    = 256
	MaxElementJSONBytes       = 512 << 10
	MaxElementBinaryBytes     = 16 << 20
	MaxElementIdentifierBytes = 1024
	MaxEnvelopeParents        = 256
)
View Source
const (
	VersionInteraction  = 2
	VersionMultimodal   = 3
	VersionElementGraph = 4
	LatestVersion       = VersionElementGraph
)
View Source
const Version = 1

Version is the frozen, legacy protocol version and remains the default. VersionInteraction adds typed interaction-act handoff. VersionMultimodal adds direct image frames and live tool-catalog updates. VersionElementGraph carries arbitrary descriptor-checked element ports rather than assuming an audio binding. Selecting a later version is explicit in Config so existing sidecars are never reinterpreted merely because the engine learned a new frame.

Variables

This section is empty.

Functions

func ElementConfigDigest

func ElementConfigDigest(config json.RawMessage) string

ElementConfigDigest binds readiness to the exact ElementConfig bytes sent in Hello. Whitespace is intentionally significant: this attests the applied deployment input, while the graph's separate bound-config fingerprint attests its management-plane origin.

func MarshalReport

func MarshalReport(report ConformanceReport) ([]byte, error)

MarshalReport renders a report as indented JSON.

func PortCapabilityName

func PortCapabilityName(direction element.Direction, name string) string

PortCapabilityName is the stable live-capability identity for one selected descriptor port.

func ValidateElementReady

func ValidateElementReady(hello, ready Message) error

ValidateElementReady binds a live v4 Ready frame to the exact Hello descriptor, selected graph ports, and required capability contracts.

func ValidatePortWireFormats

func ValidatePortWireFormats(valueType element.Type, formats []WireFormat) error

ValidatePortWireFormats checks formats against the selected graph type.

Types

type ArtifactIdentity

type ArtifactIdentity struct {
	ID       string `json:"id"`
	Revision string `json:"revision,omitempty"`
	Digest   string `json:"digest,omitempty"`
}

ArtifactIdentity names immutable runtime, provider, or adapter material. It intentionally mirrors the management-plane shape without importing the graph runtime into the process-boundary protocol.

func (ArtifactIdentity) Validate

func (artifact ArtifactIdentity) Validate() error

Validate rejects mutable selectors and identities that cannot be attested.

type Capability

type Capability string

Capability names something a sidecar can do. The engine reads these to decide what it must supply itself, which is what makes a partial implementation useful rather than broken.

const (
	// CapabilityNativeVAD means the model detects voice activity itself. A
	// sidecar without it gets an engine-owned floor.
	CapabilityNativeVAD Capability = "native_vad"
	// CapabilityTranscript means the model reports what it heard.
	CapabilityTranscript Capability = "transcript"
	// CapabilityTextInjection means text can be added to the model's context
	// between turns. Without it, a background reasoner cannot reach the model
	// at all, and the binding must fall back to an explicit hand-off.
	CapabilityTextInjection Capability = "text_injection"
	// CapabilityVisualInput means protocol-v3 image frames reach the model as
	// pixels. A narrated screen does not satisfy this capability.
	CapabilityVisualInput Capability = "visual_input"
	// CapabilityTools means the model can request function calls.
	CapabilityTools Capability = "tools"
	// CapabilityBargeIn means the model handles overlap itself.
	CapabilityBargeIn Capability = "barge_in"
	// CapabilityFullDuplex means the model can listen and speak at once. Floor
	// and interaction ownership are selected independently by the binding.
	CapabilityFullDuplex Capability = "full_duplex"
	// CapabilityNativeInteraction means the model chooses conversational acts
	// from its own multimodal state. It is independent of full duplex and of
	// native VAD: those are capabilities a model often has alongside it, not
	// synonyms for it.
	CapabilityNativeInteraction Capability = "native_interaction"
	// CapabilityInteractionActs means the sidecar accepts protocol-v2 typed
	// plans from an external interaction controller.
	CapabilityInteractionActs Capability = "interaction_acts"
)

type CapabilityIdentity

type CapabilityIdentity struct {
	Name     string            `json:"name"`
	Contract string            `json:"contract,omitempty"`
	Provider ArtifactIdentity  `json:"provider"`
	Adapter  *ArtifactIdentity `json:"adapter,omitempty"`
}

CapabilityIdentity is one live capability selected for this graph node. Provider and adapter remain independent evidence: a protocol adapter change is a changed treatment even when the model artifact is unchanged.

func CanonicalCapabilities

func CanonicalCapabilities(source []CapabilityIdentity) ([]CapabilityIdentity, error)

CanonicalCapabilities validates, clones, and deterministically orders a complete live capability set.

type CapabilityRequirement

type CapabilityRequirement struct {
	Name     string `json:"name"`
	Contract string `json:"contract,omitempty"`
}

CapabilityRequirement is an exact capability name and optional contract that a deployment must prove during readiness.

type Client

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

Client is one connection to a sidecar.

func Dial

func Dial(ctx context.Context, config Config, hello Message) (*Client, error)

Dial starts or connects to a sidecar and completes the handshake.

func (*Client) Audio

func (client *Client) Audio(payload []byte) error

Audio sends one input frame.

func (*Client) Close

func (client *Client) Close() error

Close ends the session and reaps the process.

func (*Client) Err

func (client *Client) Err() error

Err reports why reading stopped.

func (*Client) Frames

func (client *Client) Frames() <-chan Message

Frames yields sidecar messages until the connection ends.

func (*Client) Image

func (client *Client) Image(payload []byte, source, mimeType string, width, height int, timestampMS int64) error

Image sends one direct visual frame. The capability and protocol checks are made here so a caller cannot mistake a silently discarded frame for vision.

func (*Client) Ready

func (client *Client) Ready() Message

Ready returns what the sidecar declared at the handshake.

func (*Client) Send

func (client *Client) Send(message Message) error

Send writes one frame to the sidecar.

type Config

type Config struct {
	// Command runs a sidecar as a child process, talking over its stdin and
	// stdout. This is the ordinary case: the engine owns the process, and its
	// lifetime is the session's.
	Command []string
	// Address connects to an already-running sidecar over TCP or a Unix
	// socket, as "tcp:host:port" or "unix:/path". Use it when the model is
	// expensive enough to load once and share.
	Address string
	// Directory is the working directory for a spawned command.
	Directory string
	// Environment is added to a spawned command's environment.
	Environment []string
	// Handshake bounds how long the engine waits for Ready. Model loading can
	// be slow, so this is generous by default.
	Handshake time.Duration
	// Shutdown bounds each graceful-close stage: writing goodbye, waiting for
	// a child process, and reaping it after a forced kill.
	Shutdown time.Duration
	// Logf receives the sidecar's own log frames and any process stderr.
	Logf func(string, ...any)
	// ProtocolVersion selects the wire contract. Zero keeps frozen v1.
	// VersionInteraction must be selected to send typed interaction acts.
	ProtocolVersion int
}

Config configures a sidecar connection.

type ConformanceCheck

type ConformanceCheck struct {
	Name     string `json:"name"`
	Required bool   `json:"required"`
	Passed   bool   `json:"passed"`
	Skipped  bool   `json:"skipped,omitempty"`
	Detail   string `json:"detail,omitempty"`
}

ConformanceCheck is one verified property.

type ConformanceOptions

type ConformanceOptions struct {
	Config Config
	// SpeechSeconds is how much audio to send before asking for a turn.
	SpeechSeconds float64
	// TurnTimeout bounds how long one turn may take.
	TurnTimeout time.Duration
}

ConformanceOptions bounds the run.

type ConformanceReport

type ConformanceReport struct {
	Suite        string               `json:"suite"`
	Passed       bool                 `json:"passed"`
	Version      int                  `json:"version"`
	Model        string               `json:"model"`
	OutputRate   int                  `json:"output_rate"`
	Capabilities []string             `json:"capabilities"`
	Element      *element.Identity    `json:"element,omitempty"`
	Runtime      *ArtifactIdentity    `json:"runtime,omitempty"`
	ConfigDigest string               `json:"applied_config_digest,omitempty"`
	Resolved     []CapabilityIdentity `json:"resolved_capabilities,omitempty"`
	Ports        []PortNegotiation    `json:"negotiated_ports,omitempty"`
	Checks       []ConformanceCheck   `json:"checks"`
	Failures     []string             `json:"failures,omitempty"`
}

ConformanceReport records what a sidecar was verified to do.

This suite is the contract. A sidecar that passes it works with the engine whatever language it is written in, and one that does not is broken before anybody spends a GPU-hour finding out. Every check states what it required, so a failure tells the author what to fix rather than that something is wrong.

func RunConformance

func RunConformance(ctx context.Context, options ConformanceOptions) ConformanceReport

RunConformance verifies one sidecar against the contract.

type ElementConformanceFixture

type ElementConformanceFixture struct {
	Runtime      ArtifactIdentity
	Provider     ArtifactIdentity
	Adapter      ArtifactIdentity
	Capabilities []CapabilityIdentity
}

ElementConformanceFixture builds a strict Ready proof for tests and minimal servers. It selects the first offered format for every port and still runs the same negotiation validator before returning it.

func (ElementConformanceFixture) Ready

func (fixture ElementConformanceFixture) Ready(hello Message) (Message, error)

type ElementSessionContract

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

ElementSessionContract is the immutable result of one v4 Hello/Ready negotiation. Both client and server use it to validate direction, type, payload lanes, media profile, byte limits, and readiness drift.

func NegotiateElementSession

func NegotiateElementSession(hello, ready Message) (*ElementSessionContract, error)

NegotiateElementSession validates the complete v4 readiness proof and returns the contract that governs all later frames.

func (*ElementSessionContract) NegotiatedPort

func (contract *ElementSessionContract) NegotiatedPort(
	direction element.Direction, name string,
) (PortNegotiation, bool)

NegotiatedPort returns a defensive copy of one selected format.

func (*ElementSessionContract) ValidateEngineFrame

func (contract *ElementSessionContract) ValidateEngineFrame(message Message) error

ValidateEngineFrame validates one post-readiness engine-to-sidecar frame.

func (*ElementSessionContract) ValidateReady

func (contract *ElementSessionContract) ValidateReady(ready Message) error

ValidateReady accepts an equivalent reordered proof and rejects any runtime, descriptor, capability, adapter, or negotiated-format drift.

func (*ElementSessionContract) ValidateSidecarFrame

func (contract *ElementSessionContract) ValidateSidecarFrame(message Message) error

ValidateSidecarFrame validates one post-readiness sidecar-to-engine frame.

type MediaFormat

type MediaFormat struct {
	Kind                MediaKind `json:"kind"`
	Encoding            string    `json:"encoding"`
	SampleFormat        string    `json:"sample_format,omitempty"`
	SampleRateHz        int       `json:"sample_rate_hz,omitempty"`
	Channels            int       `json:"channels,omitempty"`
	MaxFrameDurationMS  int       `json:"max_frame_duration_ms,omitempty"`
	MaxWidth            int       `json:"max_width,omitempty"`
	MaxHeight           int       `json:"max_height,omitempty"`
	MaxFrameRateMilliHz int       `json:"max_frame_rate_millihz,omitempty"`
}

MediaFormat is one exact, bounded profile offered for a selected port. A Ready frame chooses the complete WireFormat containing it; negotiation never relies on omitted fields meaning provider-specific defaults.

type MediaFrameMetadata

type MediaFrameMetadata struct {
	Kind             MediaKind `json:"kind"`
	Encoding         string    `json:"encoding"`
	SampleFormat     string    `json:"sample_format,omitempty"`
	SampleRateHz     int       `json:"sample_rate_hz,omitempty"`
	Channels         int       `json:"channels,omitempty"`
	FrameDurationMS  int       `json:"frame_duration_ms,omitempty"`
	Width            int       `json:"width,omitempty"`
	Height           int       `json:"height,omitempty"`
	FrameRateMilliHz int       `json:"frame_rate_millihz,omitempty"`
}

MediaFrameMetadata is the protocol-level description of one binary media body. It is deliberately separate from the element payload JSON: transport conformance must not depend on guessing fields in provider-specific values. Audio rate/channel identities are exact while duration is bounded by the negotiated maximum. Video encoding is exact while geometry and rate are bounded by the negotiated maxima.

func (MediaFrameMetadata) Validate

func (metadata MediaFrameMetadata) Validate() error

Validate rejects incomplete, cross-kind, or unbounded frame metadata.

type MediaKind

type MediaKind string

MediaKind is deliberately small: files and other opaque binary values may negotiate a binary PayloadMode without pretending to be live media.

const (
	MediaAudio MediaKind = "audio"
	MediaVideo MediaKind = "video"
)

func MediaKindForType

func MediaKindForType(value element.Type) (MediaKind, bool, error)

MediaKindForType is a convenience for deployment adapters that want to propose standard media defaults. It is not protocol authority: protocol v4 accepts arbitrary concrete port types, and only the explicit WireFormat negotiated for a port decides whether that port has a live-media lane. A type containing both standard kinds is ambiguous to this convenience classifier and must be configured explicitly.

type Message

type Message struct {
	Type         MessageType `json:"type"`
	PayloadBytes int         `json:"payload_bytes,omitempty"`

	// Hello and Ready.
	Version      int      `json:"version,omitempty"`
	Model        string   `json:"model,omitempty"`
	SampleRate   int      `json:"sample_rate,omitempty"`
	OutputRate   int      `json:"output_rate,omitempty"`
	Instructions string   `json:"instructions,omitempty"`
	Voice        string   `json:"voice,omitempty"`
	Capabilities []string `json:"capabilities,omitempty"`
	Tools        []Tool   `json:"tools,omitempty"`

	// Generic element handshake and frames (protocol v4). The full descriptor
	// is confirmed at readiness so a package declaration cannot silently drift
	// from the process that actually started. SelectedPorts is the graph's
	// active observation/action surface, not everything the implementation is
	// theoretically capable of supporting.
	ElementDescriptor    *element.Descriptor     `json:"element_descriptor,omitempty"`
	ElementConfig        json.RawMessage         `json:"element_config,omitempty"`
	AppliedConfigDigest  string                  `json:"applied_config_digest,omitempty"`
	SelectedPorts        []PortSelection         `json:"selected_ports,omitempty"`
	RequiredCapabilities []CapabilityRequirement `json:"required_capabilities,omitempty"`
	RuntimeArtifact      ArtifactIdentity        `json:"runtime_artifact,omitempty"`
	ResolvedCapabilities []CapabilityIdentity    `json:"resolved_capabilities,omitempty"`
	NegotiatedPorts      []PortNegotiation       `json:"negotiated_ports,omitempty"`
	Port                 string                  `json:"port,omitempty"`
	Envelope             *WireEnvelope           `json:"envelope,omitempty"`
	// Selected ownership (protocol v2). Capabilities say what the stack can
	// do; these fields tell a sidecar which available provider is active.
	InteractionOwner string `json:"interaction_owner,omitempty"`
	FloorOwner       string `json:"floor_owner,omitempty"`

	// Transcript, text, and log.
	Text  string `json:"text,omitempty"`
	Final bool   `json:"final,omitempty"`
	Level string `json:"level,omitempty"`

	// Text injection.
	Role string `json:"role,omitempty"`

	// Tool call and result.
	CallID    string          `json:"call_id,omitempty"`
	Name      string          `json:"name,omitempty"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
	Output    json.RawMessage `json:"output,omitempty"`
	Error     string          `json:"error,omitempty"`

	// Turn end. Empty means the model finished what it was saying;
	// TurnInterrupted means it stopped because the user took the floor, which
	// the engine reports to clients as a cancelled response.
	TurnStatus string `json:"turn_status,omitempty"`

	// Errors.
	Code  string `json:"code,omitempty"`
	Fatal bool   `json:"fatal,omitempty"`

	// Timing.
	TimestampMS int64  `json:"timestamp_ms,omitempty"`
	Source      string `json:"source,omitempty"`
	MIMEType    string `json:"mime_type,omitempty"`
	Width       int    `json:"width,omitempty"`
	Height      int    `json:"height,omitempty"`

	// Typed interaction plan (protocol v2).
	Act         string  `json:"act,omitempty"`
	Policy      string  `json:"policy,omitempty"`
	EvidenceRef string  `json:"evidence_ref,omitempty"`
	Floor       string  `json:"floor,omitempty"`
	DeadlineMS  int64   `json:"deadline_ms,omitempty"`
	Confidence  float64 `json:"confidence,omitempty"`
	Abstained   bool    `json:"abstained,omitempty"`

	// Payload is the binary body. It is never marshalled into the header.
	Payload []byte `json:"-"`
}

Message is one frame. Payload is carried out of band and is not part of the JSON; it is populated by the reader and consumed by the writer.

func StandardElementConformanceHello

func StandardElementConformanceHello() Message

StandardElementConformanceHello returns the bounded descriptor-backed v4 probe used by RunConformance. A sidecar running in conformance mode first returns an "ok" result for an ordinary typed request, then proves typed cancellation on a second request. Both results retain the request run and causal identities; the canceled result also names the interrupt frame.

func (Message) Clone

func (message Message) Clone() Message

Clone returns an independent message suitable for retaining as a readiness baseline or handing to an untrusted session implementation.

func (Message) Has

func (message Message) Has(capability Capability) bool

Has reports whether a ready frame declared a capability.

func (Message) Message

func (message Message) Message() string

Message returns an error frame's human-readable text.

func (Message) Validate

func (message Message) Validate() error

Validate rejects a malformed frame before it reaches either side.

The checks are deliberately about structure rather than about semantics: a sidecar author debugging their implementation should get "audio needs a payload" rather than a silent hang three seconds later.

type MessageType

type MessageType string

MessageType names one frame.

const (
	// TypeHello opens a session and carries its configuration. It is always
	// the first message, and a sidecar must answer with Ready or Error.
	TypeHello MessageType = "hello"
	// TypeAudio carries input PCM16 at the negotiated rate.
	TypeAudio MessageType = "audio"
	// TypeImage carries one encoded JPEG or PNG frame. It is protocol v3: the
	// model sees pixels directly rather than a narration standing in for them.
	TypeImage MessageType = "image"
	// TypeToolsUpdate replaces the live function catalog after session.update.
	// A Realtime binding starts before the client's tool declaration arrives,
	// so a hello-only catalog would always be stale in production.
	TypeToolsUpdate MessageType = "tools_update"
	// TypeText injects text into the model's context without asking it to
	// respond. It is how a background reasoner's answer reaches a model that
	// owns its own voice.
	TypeText MessageType = "text"
	// TypeCommit closes the input audio buffer: the client has declared its
	// turn over rather than waiting for silence. A sidecar whose model owns
	// its own floor decides for itself what to do about that; one that does
	// not can ignore it, because the engine has already ended the turn.
	TypeCommit MessageType = "commit"
	// TypeRespond asks the model to produce a turn now.
	TypeRespond MessageType = "respond"
	// TypeInterrupt stops generation at the model's next safe point.
	TypeInterrupt MessageType = "interrupt"
	// TypeInteractionAct carries a policy decision rather than collapsing it
	// into respond or interrupt. It is available in protocol v2 when the
	// sidecar declares CapabilityInteractionActs.
	TypeInteractionAct MessageType = "interaction_act"
	// TypeToolResult returns the outcome of a call the model requested.
	TypeToolResult MessageType = "tool_result"
	// TypeBye ends the session cleanly.
	TypeBye MessageType = "bye"
	// TypeElementFrame carries one envelope on one descriptor-declared port.
	// It is symmetric: the engine sends frames only to input ports and the
	// sidecar sends frames only from output ports. Trigger, interrupt, timing,
	// terminal, and state semantics remain in the port's element.Type rather
	// than being collapsed into transport-specific message kinds.
	TypeElementFrame MessageType = "element_frame"
)

Engine to sidecar.

const (
	// TypeReady answers Hello and declares what this sidecar can do.
	TypeReady MessageType = "ready"
	// TypeSpeechStarted and TypeSpeechStopped report model-native voice
	// activity. A sidecar that has no native detector never sends them, and
	// the engine keeps the floor.
	TypeSpeechStarted MessageType = "speech_started"
	TypeSpeechStopped MessageType = "speech_stopped"
	// TypeTranscript reports what the model heard.
	TypeTranscript MessageType = "transcript"
	// TypeTextDelta and TypeTextDone report what the model is saying, as text.
	TypeTextDelta MessageType = "text_delta"
	TypeTextDone  MessageType = "text_done"
	// TypeOutputAudio carries output PCM16 at the declared rate.
	TypeOutputAudio MessageType = "output_audio"
	// TypeTurnDone marks the end of one model turn.
	TypeTurnDone MessageType = "turn_done"
	// TurnInterrupted is the turn_done status of a turn the model stopped
	// because the user took the floor.
	TurnInterrupted = "interrupted"
	// TypeToolCall reports a call the model wants made. A sidecar that cannot
	// call tools never sends it.
	TypeToolCall MessageType = "tool_call"
	// TypeError reports a failure. It does not end the session unless Fatal.
	TypeError MessageType = "error"
	// TypeLog carries a diagnostic line, so a sidecar's own logging does not
	// have to fight for stderr with the process that started it.
	TypeLog MessageType = "log"
)

Sidecar to engine.

type PayloadMode

type PayloadMode string

PayloadMode says which payload lanes one negotiated port frame must use. The envelope and its correlation metadata always remain in the JSON header.

const (
	PayloadJSON       PayloadMode = "json"
	PayloadBinary     PayloadMode = "binary"
	PayloadJSONBinary PayloadMode = "json_binary"
)

type PortNegotiation

type PortNegotiation struct {
	Name      string            `json:"name"`
	Direction element.Direction `json:"direction"`
	Format    WireFormat        `json:"format"`
}

PortNegotiation is the exact format selected by Ready for one Hello port.

type PortSelection

type PortSelection struct {
	Name      string            `json:"name"`
	Direction element.Direction `json:"direction"`
	Type      element.Type      `json:"type"`
	Formats   []WireFormat      `json:"formats"`
}

PortSelection tells a generic sidecar which descriptor ports the mounted graph actually connected. Direction is relative to the element.

func JSONPortSelection

func JSONPortSelection(name string, direction element.Direction, valueType element.Type) PortSelection

JSONPortSelection constructs the ordinary non-binary v4 port offer.

type Reader

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

Reader parses frames from a stream.

func NewReader

func NewReader(input io.Reader) *Reader

NewReader wraps a stream.

func (*Reader) Read

func (reader *Reader) Read() (Message, error)

Read returns the next frame, or io.EOF at the end of the stream.

type Tool

type Tool struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Parameters  json.RawMessage `json:"parameters"`
}

Tool is a function definition handed to a sidecar.

type WireEnvelope

type WireEnvelope struct {
	Type              element.Type        `json:"type"`
	ItemID            string              `json:"item_id"`
	SessionID         string              `json:"session_id,omitempty"`
	SourceID          string              `json:"source_id,omitempty"`
	OpportunityID     string              `json:"opportunity_id,omitempty"`
	RunID             string              `json:"run_id,omitempty"`
	Sequence          uint64              `json:"sequence,omitempty"`
	CaptureNS         uint64              `json:"capture_ns,omitempty"`
	ReceiveNS         uint64              `json:"receive_ns,omitempty"`
	TraceID           string              `json:"trace_id,omitempty"`
	CancellationScope string              `json:"cancellation_scope,omitempty"`
	CausalParents     []string            `json:"causal_parents,omitempty"`
	Media             *MediaFrameMetadata `json:"media,omitempty"`
	JSON              json.RawMessage     `json:"json,omitempty"`
}

WireEnvelope carries the language-neutral portion of element.Envelope. JSON and Payload are owned by Message: JSON is suitable for ordinary values while Payload preserves a zero-copy-friendly binary lane for media codecs.

func FromEnvelope

func FromEnvelope(source element.Envelope, data json.RawMessage) WireEnvelope

FromEnvelope converts metadata without interpreting payload semantics.

func (WireEnvelope) Clone

func (wire WireEnvelope) Clone() WireEnvelope

Clone returns an independent wire envelope.

func (WireEnvelope) Envelope

func (wire WireEnvelope) Envelope(payload any) element.Envelope

Envelope converts metadata and attaches a codec-decoded immutable payload.

type WireFormat

type WireFormat struct {
	PayloadMode    PayloadMode  `json:"payload_mode"`
	MaxJSONBytes   int          `json:"max_json_bytes,omitempty"`
	MaxBinaryBytes int          `json:"max_binary_bytes,omitempty"`
	Media          *MediaFormat `json:"media,omitempty"`
}

WireFormat combines payload-lane rules, byte limits, and an optional live media profile. Maxima are part of the selected identity, so peers cannot silently raise allocation limits after readiness.

func CloneWireFormats

func CloneWireFormats(source []WireFormat) []WireFormat

CloneWireFormats returns recursively independent format offers.

func JSONWireFormat

func JSONWireFormat() WireFormat

JSONWireFormat is the strict default for ordinary typed values.

func (WireFormat) Equal

func (format WireFormat) Equal(other WireFormat) bool

Equal reports whether two formats describe the same negotiated wire contract, including payload limits and the complete media profile.

type Writer

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

Writer serialises frames onto a stream.

func NewWriter

func NewWriter(output io.Writer) *Writer

NewWriter wraps a stream.

func (*Writer) Write

func (writer *Writer) Write(message Message) error

Write validates and emits one frame. It is safe for concurrent use: audio and control messages come from different goroutines, and a frame interleaved with another frame's payload is an unrecoverable stream.

Jump to

Keyboard shortcuts

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