rpc

package
v0.0.0-...-39b1c55 Latest Latest
Warning

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

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

Documentation

Overview

pkg/rpc/client.go

Index

Constants

This section is empty.

Variables

View Source
var (
	// RPCUnknownError represents an unexpected error, which is likely a bug in the aRPC library.
	// However, it's possible that the error is caused by network issues or other external factors.
	RPCUnknownError = RPCErrorType{Name: "unknown"}
	// RPCFailError represents an error correctly handled by the aRPC library, such as
	// (1) service/method not found
	RPCFailError = RPCErrorType{Name: "fail"}
)

Functions

This section is empty.

Types

type Client

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

Client represents an RPC client with a transport and serializer.

func NewClient

func NewClient(serializer serializer.Serializer, addr string) (*Client, error)

NewClient creates a new Client using the given serializer and target address. The client will create a QUIC connection to the server.

func NewClientWithLocalAddr

func NewClientWithLocalAddr(serializer serializer.Serializer, addr, localAddr string) (*Client, error)

NewClientWithLocalAddr creates a new Client using the given serializer, target address, and local address. Note: For QUIC, the local address is not used in the same way as UDP. This function is kept for API compatibility but the localAddr parameter is ignored.

func (*Client) Call

func (c *Client) Call(ctx context.Context, service, method string, req any, resp any) error

Call makes an RPC call

func (*Client) GetTransport

func (c *Client) GetTransport() *transport.QUICTransport

GetTransport returns the underlying transport for advanced operations

func (*Client) Transport

func (c *Client) Transport() *transport.QUICTransport

Transport returns the underlying QUIC transport for cleanup purposes

type MethodDesc

type MethodDesc struct {
	MethodName string
	Handler    MethodHandler
}

MethodDesc represents an RPC service's method specification.

type MethodHandler

type MethodHandler func(srv any, ctx context.Context, dec func(any) error) (resp any, err error)

MethodHandler defines the function signature for handling an RPC method.

type RPCError

type RPCError struct {
	Type   RPCErrorType
	Reason string
}

func (*RPCError) Error

func (e *RPCError) Error() string

type RPCErrorType

type RPCErrorType struct {
	Name string
}

type Server

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

Server is the core RPC server handling transport, serialization, and registered services.

func NewServer

func NewServer(addr string, serializer serializer.Serializer) (*Server, error)

NewServer initializes a new Server instance with the given address and serializer.

func (*Server) GetTransport

func (s *Server) GetTransport() *transport.QUICTransport

GetTransport returns the underlying transport for advanced operations

func (*Server) RegisterService

func (s *Server) RegisterService(desc *ServiceDesc, impl any)

RegisterService registers a service and its methods with the server.

func (*Server) Start

func (s *Server) Start()

Start begins listening for incoming RPC requests, dispatching to the appropriate service/method handler.

type ServiceDesc

type ServiceDesc struct {
	ServiceImpl any
	ServiceName string
	Methods     map[string]*MethodDesc
}

ServiceDesc describes an RPC service, including its implementation and methods.

type ServiceRegistry

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

ServiceRegistry maintains mappings from service/method names to IDs for client-side ID lookup

func NewServiceRegistry

func NewServiceRegistry() *ServiceRegistry

NewServiceRegistry creates a new ServiceRegistry

func (*ServiceRegistry) GetMethodID

func (r *ServiceRegistry) GetMethodID(serviceName, methodName string) (uint32, bool)

GetMethodID looks up a method ID by service and method names

func (*ServiceRegistry) GetMethodIDOrPanic

func (r *ServiceRegistry) GetMethodIDOrPanic(serviceName, methodName string) uint32

GetMethodIDOrPanic looks up a method ID by service and method names and panics if not found

func (*ServiceRegistry) GetServiceID

func (r *ServiceRegistry) GetServiceID(serviceName string) (uint32, bool)

GetServiceID looks up a service ID by name

func (*ServiceRegistry) GetServiceIDOrPanic

func (r *ServiceRegistry) GetServiceIDOrPanic(serviceName string) uint32

GetServiceIDOrPanic looks up a service ID by name and panics if not found

func (*ServiceRegistry) RegisterService

func (r *ServiceRegistry) RegisterService(serviceName string, serviceID uint32, methodMap map[string]uint32)

RegisterService registers a service and its methods in the registry

Jump to

Keyboard shortcuts

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