feat: 添加 []byte ↔ bytes 支持(base64 透明编解码)
- Python 侧:_decode_bytes_args 根据函数注解自动解码入参,_bytes_encode 自动编码 bytes 返回值 - _cast 支持 bytes 类型(call_go[bytes] 返回值解码) - 流式输出同步支持 chan []byte(每个 chunk 独立编解码) - example/worker.py 新增 bytes_reverse / bytes_concat / bytes_chunks 示例 - example/main.go 新增对应演示用例 - README 补充类型表 []byte 行及完整使用章节
This commit is contained in:
@@ -98,6 +98,28 @@ def process_users(users: Iterator[dict]) -> Iterator[dict]:
|
||||
yield {"id": u["id"], "name": u["name"].upper(), "score": u["score"] * 2}
|
||||
|
||||
|
||||
# ── []byte / bytes 示例 ──────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@expose
|
||||
def bytes_reverse(data: bytes) -> bytes:
|
||||
"""接收 []byte,返回翻转后的 []byte"""
|
||||
return data[::-1]
|
||||
|
||||
|
||||
@expose
|
||||
def bytes_concat(a: bytes, b: bytes) -> bytes:
|
||||
"""接收两个 []byte 参数,返回拼接结果"""
|
||||
return a + b
|
||||
|
||||
|
||||
@expose
|
||||
def bytes_chunks(data: bytes, size: int):
|
||||
"""流式输出:将 []byte 按 size 切分,逐块 yield(对应 Go Invoke[chan []byte])"""
|
||||
for i in range(0, len(data), size):
|
||||
yield data[i:i + size]
|
||||
|
||||
|
||||
# ── Server 全双工示例 ────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user