代码拉取完成,页面将自动刷新
package Receivers
import (
"gitee.com/ling-bin/network/netConn"
)
/// 按照开始结束符来粘包(单字节版)
type SpliceSymbolReceiver struct {
StartSymbol byte
FinishSymbol byte
}
//按照开始结束符来粘包
func NewSpliceSymbolReceiver(startSymbol byte,finishSymbol byte) *SpliceSymbolReceiver {
return &SpliceSymbolReceiver{
StartSymbol: startSymbol,
FinishSymbol: finishSymbol,
}
}
//分包逻辑
func (s *SpliceSymbolReceiver) Receiver(conn netConn.IConnection, buffer []byte) ([]byte,int,bool) {
bfLen := len(buffer)
startIndex := 0
isOk := false
for i := 0; i < bfLen; i++ {
if buffer[i] == s.StartSymbol {
startIndex = i
} else if buffer[i] == s.FinishSymbol {
cacheBf := conn.GetBytesCache()
cacheBf.Write(buffer[startIndex:(i + 1)])
data := cacheBf.Bytes()
//fmt.Printf( "[分包结果]=======:%p\n", data)
conn.OnReceiveCompleted(data)
//fmt.Printf( "[分包缓存]=======:%p\n", cacheBf)
cacheBf.Reset()
startIndex = i + 1
isOk = true
break
}
}
if startIndex < bfLen {
return buffer[startIndex:], startIndex, isOk
}
return nil, startIndex, isOk
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。