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.
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
}