Documentation
¶
Overview ¶
Package jsonline binds ext.io.pc/v1 to bounded newline-delimited JSON over a caller-owned duplex connection (for example, local IPC or process pipes). It neither starts processes nor chooses native endpoints.
Index ¶
- Constants
- func NewFuncGuest(descriptor plugin.Descriptor, fn Func, options FuncOptions) (*plugin.Guest, error)
- func Profile() plugin.BackendProfile
- func Serve(ctx context.Context, conn io.ReadWriteCloser, descriptor plugin.Descriptor, ...) error
- func ServeFunc(ctx context.Context, descriptor plugin.Descriptor, fn Func, ...) error
- func ServeGuest(ctx context.Context, conn io.ReadWriteCloser, guest plugin.Endpoint) error
- func ServeStdio(ctx context.Context, guest plugin.Endpoint) error
- type Client
- type Func
- type FuncOptions
- type Handler
- type Server
Constants ¶
const FailureCode = "provider_error"
FailureCode is the code of the RemoteError produced for an ordinary error.
const MaxFailureMessageBytes = 4096
MaxFailureMessageBytes bounds an ordinary error's message.
Variables ¶
This section is empty.
Functions ¶
func NewFuncGuest ¶
func NewFuncGuest(descriptor plugin.Descriptor, fn Func, options FuncOptions) (*plugin.Guest, error)
NewFuncGuest adapts fn to a guest endpoint for descriptor. An error that is (or wraps) a *plugin.RemoteError is sent as is; any other error becomes RemoteError{Code: FailureCode, Message: err.Error()} cut to MaxFailureMessageBytes on a character boundary, or a generic message when RedactErrors is set.
func Profile ¶
func Profile() plugin.BackendProfile
func Serve ¶
func Serve(ctx context.Context, conn io.ReadWriteCloser, descriptor plugin.Descriptor, handler Handler) error
Serve requires hello first and validates every subsequent request against the descriptor before calling handler. Calls are sequential. It owns conn; cancellation closes it. Domain payloads and error text are never logged.
func ServeFunc ¶
func ServeFunc(ctx context.Context, descriptor plugin.Descriptor, fn Func, options FuncOptions) error
ServeFunc serves fn for descriptor on this process's stdin and stdout until the stream ends; see ServeStdio for the stream rules. Call once from main.
func ServeGuest ¶
ServeGuest binds a shared guest endpoint to a JSON-line connection. This owns only conn; the embedding application owns the endpoint's lifecycle.
A reader goroutine routes frames: requests go to the call loop, which handles one call at a time, and reverse responses go to the reverse call that waits for them. A handler that blocks on a reverse call therefore never stops the reader, so a serialized connection cannot deadlock. Handlers reach the host with plugin.ReverseFrom and plugin.SessionReverseFrom, and report progress with plugin.ProgressFrom.
func ServeStdio ¶
ServeStdio serves a standalone guest on stdin/stdout, including Go WASI commands. It owns and closes both streams. Send diagnostics to stderr only; stdout is reserved for the Ext protocol. Call once from the guest's main.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Connections must allow Close concurrently with Read/Write and unblock both. The client owns the supplied connection. One client belongs to one session.
One call is in flight at a time. While it is, the guest may send progress frames and reverse requests, and at any time after the handshake it may send session-scoped reverse requests; a reader goroutine, started with the first call, routes them so a blocked call never stops reverse calls from being served.
func NewClient ¶
func NewClient(conn io.ReadWriteCloser) *Client
func (*Client) SetReverse ¶
func (c *Client) SetReverse(h plugin.ReverseHost)
SetReverse registers the host that serves the guest's reverse calls. Open calls it before the handshake when the host configured Reverse.
type Func ¶
Func handles one call for a guest that addresses operations by a single string, Contract.Name + "." + Operation. payload is the request payload (nil when absent). The result must be JSON-encodable.
type FuncOptions ¶
type FuncOptions struct {
// RedactErrors replaces the message of an ordinary error with a generic
// one. By default the message reaches the host (as untrusted diagnostics).
RedactErrors bool
// MaxCallDuration is the guest-owned bound; zero uses plugin.DefaultTimeout.
MaxCallDuration time.Duration
}
FuncOptions tunes ServeFunc and NewFuncGuest.
type Handler ¶
Handler performs consumer authorization and executes one domain call. It must honor ctx. Return a RemoteError to expose a deliberate public error; other errors are reduced to a stable generic response.