rpc

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package rpc 定义RPC调用相关的类型和接口 包含请求上下文、响应写入器、处理函数等

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Conn    *conn.Connection // 连接对象
	ID      uint64           // 请求ID
	Route   string           // 路由信息
	Payload []byte           // 请求数据
	H       Handler          // 处理函数
	// contains filtered or unexported fields
}

Context RPC请求上下文,包含请求信息和响应方法

func NewContext

func NewContext(cn *conn.Connection, id uint64, route string, payload []byte, h Handler) *Context

NewContext 创建新的请求上下文

func (*Context) HandleIncomingFrame

func (c *Context) HandleIncomingFrame(frame *protocol.Frame)

HandleIncomingFrame 处理传入的帧(用于双向通信)

func (*Context) ReceiveMessage

func (c *Context) ReceiveMessage() ([]byte, error)

ReceiveMessage 接收客户端消息(双向通信,非阻塞)

func (*Context) ReceiveMessageBlocking

func (c *Context) ReceiveMessageBlocking() ([]byte, error)

ReceiveMessageBlocking 接收客户端消息(双向通信,阻塞)

func (*Context) Reply

func (c *Context) Reply(b []byte) error

Reply 发送同步响应

func (*Context) SendMessage

func (c *Context) SendMessage(b []byte) error

SendMessage 发送消息到客户端(双向通信)

func (*Context) Stream

func (c *Context) Stream() *ResponseWriter

Stream 获取流式响应写入器

type Handler

type Handler func(*Context)

Handler RPC请求处理函数类型

type ResponseWriter

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

ResponseWriter 响应写入器,用于发送响应数据

func NewResponseWriter

func NewResponseWriter(cn *conn.Connection, id uint64, route []byte) *ResponseWriter

NewResponseWriter 创建新的响应写入器

func (*ResponseWriter) Close

func (w *ResponseWriter) Close()

Close 关闭双向通信通道

func (*ResponseWriter) ReceiveMessage

func (w *ResponseWriter) ReceiveMessage() ([]byte, error)

ReceiveMessage 接收客户端消息(双向通信)

func (*ResponseWriter) ReceiveMessageBlocking

func (w *ResponseWriter) ReceiveMessageBlocking() ([]byte, error)

ReceiveMessageBlocking 阻塞接收客户端消息(双向通信)

func (*ResponseWriter) SendMessage

func (w *ResponseWriter) SendMessage(b []byte) error

SendMessage 发送消息到客户端(双向通信)

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(b []byte) error

Write 写入完整响应数据

func (*ResponseWriter) WriteChunk

func (w *ResponseWriter) WriteChunk(b []byte, end bool) error

WriteChunk 写入流式响应数据块

Jump to

Keyboard shortcuts

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