first commit

This commit is contained in:
2026-04-10 09:24:28 +08:00
commit a92abca252
10 changed files with 1645 additions and 0 deletions

26
protocol.go Normal file
View File

@@ -0,0 +1,26 @@
package gobridge
import "encoding/json"
// 消息类型常量
const (
TypeCall = "call" // Go → Python: 调用请求
TypeResult = "result" // Python → Go: 调用结果
TypeError = "error" // 双向: 错误响应
TypeChunk = "chunk" // 双向: 流数据块
TypeEnd = "end" // 双向: 流结束标记
TypeCancel = "cancel" // Go → Python: 取消正在执行的调用ctx 取消时发送)
)
// Message 是 Go 与 Python 之间传输的消息结构
// 使用 4 字节大端长度前缀 + JSON 编码
type Message struct {
ID uint64 `json:"id"`
Type string `json:"type"`
Method string `json:"method,omitempty"`
Args json.RawMessage `json:"args,omitempty"`
StreamInput bool `json:"stream_input,omitempty"` // 是否有流式输入参数
StreamArgIdx int `json:"stream_arg_idx,omitempty"` // 流式参数在 args 中的下标
Data json.RawMessage `json:"data,omitempty"` // 结果/数据块内容
Error string `json:"error,omitempty"`
}