Files
bl/common/cool/coolconfig/runtime_id.go
xinian 7d49aaa212 refactor: 重构运行时ID组合逻辑
将硬编码的 ID 组合逻辑(100000*OnlineID + Port)提取为通用函数 ComposeRuntimeID,
使用 16 位位移掩码优化,并新增辅助方法与类型转换。同时修复踢人流程中的资源清理问题。
2026-04-28 04:03:13 +08:00

23 lines
794 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package coolconfig
import "github.com/gogf/gf/v2/util/gconv"
const runtimeIDPortBits = 16
const runtimeIDPortMask uint32 = 0xFFFF
// ComposeRuntimeID 将 serverID 和 port 组合成运行时复合 ID。
// 高 16 位保存 serverID低 16 位保存 port。
func ComposeRuntimeID(serverID, port uint32) uint32 {
return ((serverID & runtimeIDPortMask) << runtimeIDPortBits) | (port & runtimeIDPortMask)
}
// SplitRuntimeID 将运行时复合 ID 拆分为 serverID 和 port。
func SplitRuntimeID(runtimeID uint32) (serverID, port uint32) {
return runtimeID >> runtimeIDPortBits, runtimeID & runtimeIDPortMask
}
// RuntimeIDString 返回运行时复合 ID 的字符串形式。
func RuntimeIDString(serverID, port uint32) string {
return gconv.String(ComposeRuntimeID(serverID, port))
}