You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package server
import (
"github.com/noahlann/nnet/internal/codec"
internalprotocol "github.com/noahlann/nnet/internal/protocol"
"github.com/noahlann/nnet/internal/protocol/nnet"
codecpkg "github.com/noahlann/nnet/pkg/codec"
"github.com/noahlann/nnet/pkg/config"
protocolpkg "github.com/noahlann/nnet/pkg/protocol"
)
// initCodecRegistry 初始化编解码器注册表
func initCodecRegistry(cfg *config.Config) codecpkg.Registry {
// 创建编解码器注册表
codecRegistry := codec.NewRegistry()
// 注册Protobuf和MessagePack编解码器如果可用
protobufCodec := codec.NewProtobufCodec()
codecRegistry.Register("protobuf", protobufCodec)
msgpackCodec := codec.NewMessagePackCodec()
codecRegistry.Register("msgpack", msgpackCodec)
return codecRegistry
}
// initProtocolManager 初始化协议管理器
// 协议管理器只管理应用层协议如nnet协议不管理传输层协议TCP、UDP、WebSocket
func initProtocolManager() protocolpkg.Manager {
// 创建协议管理器
protocolManager := internalprotocol.NewManager()
// 注册nnet协议应用层协议
nnetProtocol := nnet.NewNNetProtocol("1.0")
protocolManager.Register(nnetProtocol)
return protocolManager
}