ipc

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package ipc implements peng's framed JSON-RPC transport for embedding hosts like peng-tui.

Frames are LSP-style: a sequence of `Header: Value\r\n` lines (only `Content-Length` is interpreted), an empty `\r\n`, then exactly Content-Length bytes of JSON payload. Multiple frames can flow in either direction over the same stream; each is self-delimited.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadFrame = errors.New("ipc: malformed frame")

ErrBadFrame is returned when the header section is malformed or Content-Length is missing/invalid.

Functions

func ReadFrame

func ReadFrame(r *bufio.Reader) ([]byte, error)

ReadFrame consumes one frame from r and returns its raw JSON payload. On EOF before any header bytes are read, returns io.EOF unwrapped so the caller can detect graceful shutdown.

Types

type FrameWriter

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

FrameWriter serializes writes to an underlying io.Writer. Multiple goroutines (request responses, stream chunks, events) post frames concurrently; the writer's mutex serializes them so they don't interleave on the wire.

func NewFrameWriter

func NewFrameWriter(w io.Writer) *FrameWriter

NewFrameWriter wraps w. Caller retains ownership of w; closing the writer is the caller's responsibility (typically the IPC server's shutdown path).

func (*FrameWriter) WriteFrame

func (fw *FrameWriter) WriteFrame(body []byte) (int, error)

WriteFrame emits header + body as one frame. Returns the byte count written and any underlying writer error.

type Server

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

Server runs the IPC dispatch loop against a server.Mux. One Server instance serves a single stdio pair (or any io.Reader/io.Writer combo — net.Pipe is used in tests).

func New

func New(mux *server.Mux, bus *eventbus.Bus, in io.Reader, out io.Writer) *Server

New returns an IPC server. bus may be nil to disable event push.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve blocks until ctx is canceled or the input stream closes. It runs the event pump in a goroutine and the read loop on the caller's goroutine.

Jump to

Keyboard shortcuts

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