rpc

package
v0.2.43 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package rpc is a small, handwritten RPC framing layer for the in-process transport. It deliberately contains no protobuf generated code and no gRPC: service stubs in sdk/go/cloudpath/v1/* build on Client and Server here, and the A4 Plugin Host can swap the underlying transport.Transport for a named pipe or Unix socket without touching service contracts.

Frame semantics (see transport.Message):

client -> server   KindUnary      one request, exactly one terminal reply
server -> client   KindResponse   terminal unary reply (Err set on failure)
client -> server   KindStreamReq  open a server stream
either direction   KindStreamMsg  stream payload
client -> server   KindStreamEnd  half-close of the client send side
server -> client   KindStreamEndTerm server finished the stream (both sides)
client -> server   KindStreamCancel cancel the whole call

Index

Constants

View Source
const (
	KindUnary         = transport.KindUnary
	KindResponse      = transport.KindResponse
	KindStreamReq     = transport.KindStreamReq
	KindStreamMsg     = transport.KindStreamMsg
	KindStreamEnd     = transport.KindStreamEnd
	KindStreamEndTerm = transport.KindStreamEndTerm
	KindStreamCancel  = transport.KindStreamCancel
)

Frame kinds mirrored from the transport package for call-site readability.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the connection-scoped RPC client. One Client multiplexes many unary calls and streams over one Transport and is safe for concurrent use.

func NewClient

func NewClient(tr transport.Transport) *Client

NewClient wraps tr and starts the receive loop.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, req any) ([]byte, error)

Call performs a unary request. resp data is JSON-marshaled; the returned bytes are the JSON-marshaled response body.

func (*Client) OpenStream

func (c *Client) OpenStream(ctx context.Context, method string, req any) (*ClientStream, error)

OpenStream starts a server-streaming (or bidi) call.

type ClientStream

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

ClientStream is the client side of one stream call.

func (*ClientStream) Cancel

func (s *ClientStream) Cancel(ctx context.Context) error

Cancel cancels the whole call; the server handler context is canceled.

func (*ClientStream) CloseSend

func (s *ClientStream) CloseSend(ctx context.Context) error

CloseSend half-closes the client send side. The server may keep sending.

func (*ClientStream) Recv

func (s *ClientStream) Recv(ctx context.Context) ([]byte, error)

Recv returns the next payload and io.EOF after the server ends the stream.

func (*ClientStream) Send

func (s *ClientStream) Send(ctx context.Context, msg any) error

Send pushes one payload (bidi streams only).

type Server

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

Server dispatches frames from one Transport to registered handlers.

func NewServer

func NewServer(tr transport.Transport) *Server

NewServer returns an empty dispatcher bound to tr.

func (*Server) HandleStream

func (s *Server) HandleStream(method string, fn func(ctx context.Context, body []byte, stream *ServerStream) error) *Server

HandleStream registers a stream handler for method.

func (*Server) HandleUnary

func (s *Server) HandleUnary(method string, fn func(ctx context.Context, body []byte) (any, error)) *Server

HandleUnary registers a unary handler for method.

func (*Server) Serve

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

Serve consumes frames until the transport closes or ctx is canceled.

type ServerStream

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

ServerStream is the server side of one stream call.

func (*ServerStream) Recv

func (s *ServerStream) Recv(ctx context.Context) ([]byte, error)

Recv reads one client payload; io.EOF once the client half-closes or cancels. Only bidi handlers should call Recv.

func (*ServerStream) Send

func (s *ServerStream) Send(ctx context.Context, msg any) error

Send pushes one payload to the client.

Jump to

Keyboard shortcuts

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