Documentation ¶
Overview ¶
定义了消息的接口
报文解析模块
Package network is a generated protocol buffer package.
It is generated from these files:
service.proto
It has these top-level messages:
Data
通用的tcp服务器
通用的websocket服务器
Index ¶
- Variables
- func RegisterServiceServer(s *grpc.Server, srv ServiceServer)
- type Config
- type Data
- type Data_Frame
- type Data_FrameType
- type Iagent
- type Iconn
- type Imessage
- type MessageInfo
- type MessageParser
- func (msgParser *MessageParser) NewMessageParser() *MessageParser
- func (msgParser *MessageParser) ReadBody(data []byte) ([]byte, error)
- func (msgParser *MessageParser) ReadBodyFull(data []byte) (uint32, uint16, []byte, error)
- func (msgParser *MessageParser) SetMsgLen(MaxMessageLen uint16, MinMessageLen uint16)
- func (msgParser *MessageParser) Write(data []byte) ([]byte, error)
- type MsgManager
- type RawMessage
- type ServiceClient
- type ServiceServer
- type Service_StreamClient
- type Service_StreamServer
- type TcpConn
- func (conn *TcpConn) Close()
- func (conn *TcpConn) LocalAddr() net.Addr
- func (conn *TcpConn) Read(b []byte) (int, error)
- func (conn *TcpConn) ReadMsg() ([]byte, error)
- func (conn *TcpConn) RemoteAddr() net.Addr
- func (conn *TcpConn) SetReadDeadline(t time.Time) error
- func (conn *TcpConn) SetWriteDeadline(t time.Time) error
- func (conn *TcpConn) WriteMsg(arg []byte) error
- type TcpServer
- type WsConn
- func (conn *WsConn) Close()
- func (conn *WsConn) LocalAddr() net.Addr
- func (conn *WsConn) ReadMsg() ([]byte, error)
- func (conn *WsConn) RemoteAddr() net.Addr
- func (conn *WsConn) SetReadDeadline(t time.Time) error
- func (conn *WsConn) SetWriteDeadline(t time.Time) error
- func (conn *WsConn) WriteMsg(arg []byte) error
- type WsServer
Constants ¶
This section is empty.
Variables ¶
View Source
var Data_FrameType_name = map[int32]string{
0: "Message",
1: "Kick",
2: "Ping",
}
View Source
var Data_FrameType_value = map[string]int32{
"Message": 0,
"Kick": 1,
"Ping": 2,
}
Functions ¶
func RegisterServiceServer ¶
func RegisterServiceServer(s *grpc.Server, srv ServiceServer)
Types ¶
type Config ¶
type Config struct { ServerAddress string // 服务地址 MaxConnNum int // 最大连接数 MaxMsgLen int // client<->gateway message上限 MinMsgLen int // client<->gateway message下限 ReadDeadline int // gateway->client读超时 WriteDeadline int // gateway->client写超时 MaxHeader int // header上限(for websocket) HttpTimeout int // http-get超时(for websocket) CertFile string // for ssl KeyFile string // for ssl MsgParser Imessage // for message Parser *MessageParser // for 报文 Gate Iagent // 网关 PendingNum int // gateway->client异步ipc队列上限 Rpm int // client->gateway流量上限/min AsyncMQ int // service->gateway异步ipc队列上限 GateWayIds uint16 // gateway本地路由id段(当前路由规则是简单的id分段规则) }
type Data ¶
type Data struct { }
func (*Data) Descriptor ¶
func (*Data) ProtoMessage ¶
func (*Data) ProtoMessage()
type Data_Frame ¶
type Data_Frame struct { Type Data_FrameType `protobuf:"varint,1,opt,name=Type,enum=network.Data_FrameType" json:"Type,omitempty"` Message []byte `protobuf:"bytes,2,opt,name=Message,proto3" json:"Message,omitempty"` }
func (*Data_Frame) Descriptor ¶
func (*Data_Frame) Descriptor() ([]byte, []int)
func (*Data_Frame) ProtoMessage ¶
func (*Data_Frame) ProtoMessage()
func (*Data_Frame) Reset ¶
func (m *Data_Frame) Reset()
func (*Data_Frame) String ¶
func (m *Data_Frame) String() string
type Data_FrameType ¶
type Data_FrameType int32
const ( Data_Message Data_FrameType = 0 Data_Kick Data_FrameType = 1 Data_Ping Data_FrameType = 2 )
func (Data_FrameType) EnumDescriptor ¶
func (Data_FrameType) EnumDescriptor() ([]byte, []int)
func (Data_FrameType) String ¶
func (x Data_FrameType) String() string
type Imessage ¶
type Imessage interface { Register(msg *RawMessage) error // 消息注册 UnRegister(msg *RawMessage) // 消息反注册 Serialize(msg RawMessage) ([]byte, error) // 序列化消息 Deserialize(date []byte) (*RawMessage, error) // 反序列化消息 }
type MessageParser ¶
type MessageParser struct {
// contains filtered or unexported fields
}
func NewMessageParser ¶
func NewMessageParser() (newMsg *MessageParser)
func (*MessageParser) NewMessageParser ¶
func (msgParser *MessageParser) NewMessageParser() *MessageParser
func (*MessageParser) ReadBody ¶
func (msgParser *MessageParser) ReadBody(data []byte) ([]byte, error)
获取body(除header)
func (*MessageParser) ReadBodyFull ¶
拆分body数据 @return 数据1(序列号),数据2(协议号),数据3(id+message),错误描述
func (*MessageParser) SetMsgLen ¶
func (msgParser *MessageParser) SetMsgLen(MaxMessageLen uint16, MinMessageLen uint16)
type MsgManager ¶
type MsgManager struct {
MsgMap map[uint16]*MessageInfo // id池:主要用于识别id对应的pb结构
}
处理器的数据结构
func (*MsgManager) Deserialize ¶
func (msgManager *MsgManager) Deserialize(data []byte) (*RawMessage, error)
for id+message goroutine safe
func (*MsgManager) Register ¶
func (msgManager *MsgManager) Register(rawM *RawMessage) error
not goroutine safe
func (*MsgManager) Serialize ¶
func (msgManager *MsgManager) Serialize(rawM RawMessage) ([]byte, error)
for id+message goroutine safe
func (*MsgManager) UnRegister ¶
func (msgManager *MsgManager) UnRegister(rawM *RawMessage)
not goroutine safe
type RawMessage ¶
type RawMessage struct { MsgId uint16 MsgData interface{} }
type ServiceClient ¶
type ServiceClient interface {
Stream(ctx context.Context, opts ...grpc.CallOption) (Service_StreamClient, error)
}
func NewServiceClient ¶
func NewServiceClient(cc *grpc.ClientConn) ServiceClient
type ServiceServer ¶
type ServiceServer interface {
Stream(Service_StreamServer) error
}
type Service_StreamClient ¶
type Service_StreamClient interface { Send(*Data_Frame) error Recv() (*Data_Frame, error) grpc.ClientStream }
type Service_StreamServer ¶
type Service_StreamServer interface { Send(*Data_Frame) error Recv() (*Data_Frame, error) grpc.ServerStream }
type TcpConn ¶
type TcpConn struct {
// contains filtered or unexported fields
}
func (*TcpConn) RemoteAddr ¶
type WsConn ¶
type WsConn struct {
// contains filtered or unexported fields
}
func (*WsConn) RemoteAddr ¶
Click to show internal directories.
Click to hide internal directories.