1 Star 0 Fork 0

可信数据/boxio_ant

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
stream.go 970 Bytes
一键复制 编辑 原始数据 按行查看 历史
tellixu 提交于 2025-01-08 14:45 +08:00 . init
package boxio
import (
"io"
)
// MessageSizeMax is a soft (recommended) maximum for network messages.
// One can write more, as the interface is a stream. But it is useful
// to bunch it up into multiple read/writes when the whole message is
// a single, large serialized object.
const MessageSizeMax = 1 << 22 // 4 MB
var (
BoxMsgIO = &BoxDataIOData{}
)
type BoxDataIOData struct {
}
// ReadMessage 读取一个BoxData消息
func (that *BoxDataIOData) ReadMessage(stream io.Reader, msg BoxData) error {
// 最大读取4M数据
r := NewBoxReader(stream, MessageSizeMax)
err := r.ReadBox(msg)
if err != nil {
return err
}
return nil
}
func (that *BoxDataIOData) WriteMessage(stream io.Writer, msg BoxData, tryCount int) error {
if tryCount <= 0 {
tryCount = 1
}
for i := 1; i <= tryCount; i++ {
w := NewBoxWriter(stream)
err := w.WriteBox(msg)
if err != nil {
if i < tryCount {
continue
}
return err
}
break
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/credata/boxio_ant.git
git@gitee.com:credata/boxio_ant.git
credata
boxio_ant
boxio_ant
fefb07e56765

搜索帮助