Documentation
¶
Overview ¶
pkg/rpc/client.go
Index ¶
- Variables
- type Client
- type MethodDesc
- type MethodHandler
- type RPCError
- type RPCErrorType
- type Server
- type ServiceDesc
- type ServiceRegistry
- func (r *ServiceRegistry) GetMethodID(serviceName, methodName string) (uint32, bool)
- func (r *ServiceRegistry) GetMethodIDOrPanic(serviceName, methodName string) uint32
- func (r *ServiceRegistry) GetServiceID(serviceName string) (uint32, bool)
- func (r *ServiceRegistry) GetServiceIDOrPanic(serviceName string) uint32
- func (r *ServiceRegistry) RegisterService(serviceName string, serviceID uint32, methodMap map[string]uint32)
Constants ¶
This section is empty.
Variables ¶
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) 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 ¶
MethodHandler defines the function signature for handling an RPC method.
type RPCError ¶
type RPCError struct {
Type RPCErrorType
Reason 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.
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