代码拉取完成,页面将自动刷新
同步操作将从 YoMo/y3-codec-golang 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package y3
import (
"errors"
"github.com/yomorun/y3-codec-golang/pkg/encoding"
"github.com/yomorun/y3-codec-golang/internal/mark"
)
func parsePayload(b []byte) (endPos int, ifNodePacket bool, np *NodePacket, pp *PrimitivePacket, err error) {
if len(b) == 0 {
return 0, false, nil, nil, errors.New("parsePacket params can not be nil")
}
pos := 0
// NodePacket
if ok := isNodePacket(b[pos]); ok {
np, endPos, err := DecodeNodePacket(b)
return endPos, true, np, nil, err
}
pp, endPos, _, err = DecodePrimitivePacket(b)
return endPos, false, nil, pp, err
}
// DecodeNodePacket parse out whole buffer to a NodePacket
func DecodeNodePacket(buf []byte) (pct *NodePacket, endPos int, err error) {
// fmt.Println(hex.Dump(buf))
pct = &NodePacket{}
if len(buf) == 0 {
return pct, 0, nil
}
nodeArr := make([]NodePacket, 0)
primArr := make([]PrimitivePacket, 0)
pos := 0
// `Tag`
tag := mark.NewTag(buf[pos])
pct.basePacket.tag = tag
pos++
// `Length`: the type is `varint`
tmpBuf := buf[pos:]
var vallen int32
codec := encoding.VarCodec{}
err = codec.DecodePVarInt32(tmpBuf, &vallen)
// _len, vallen, err := encoding.Upvarint(buf, pos)
if err != nil {
return nil, 0, err
}
pct.basePacket.length = uint32(vallen)
pos += codec.Size
// `raw` is pct.Length() length
vl := int(vallen)
endPos = pos + vl
pct.basePacket.valBuf = make([]byte, vl)
copy(pct.basePacket.valBuf, buf[pos:endPos])
// Parse value to Packet
for {
// fmt.Println("------>pos:", pos, ", endPos:", endPos, ", len(buf)", len(buf))
if pos >= endPos || pos >= len(buf) {
// fmt.Println("===GAME OVER===")
break
}
_p, isNode, np, pp, err := parsePayload(buf[pos:endPos])
pos += _p
if err != nil {
return nil, 0, err
}
if isNode {
nodeArr = append(nodeArr, *np)
} else {
primArr = append(primArr, *pp)
}
}
pct.NodePackets = nodeArr
pct.PrimitivePackets = primArr
return pct, endPos, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。