1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-29 07:10:25 +08:00

feat: impl. new protol design & new head

This commit is contained in:
源文雨
2025-03-12 22:20:02 +09:00
parent 60209117b7
commit f4fd9b1423
49 changed files with 1643 additions and 1137 deletions

22
gold/link/event.go Normal file
View File

@@ -0,0 +1,22 @@
package link
import (
"strconv"
"github.com/fumiama/WireGold/gold/head"
"github.com/fumiama/orbyte/pbuf"
)
// 事件分发器
var dispachers map[uint8]EventDispacher = make(map[uint8]EventDispacher)
type EventDispacher func(header *head.Packet, peer *Link, data pbuf.Bytes)
// AddProto is thread unsafe. Use in init() only.
func AddProto(p uint8, d EventDispacher) {
_, ok := dispachers[p]
if ok {
panic("proto " + strconv.Itoa(int(p)) + " has been registered")
}
dispachers[p] = d
}