fnet

package module
v0.0.0-...-9f872dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

README

fnet

##一个通用高效的游戏网络库
1.支持websocket 和原生tcp socket
2.支持断线重连

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Codecs are codecs supported by rpc. You can add customized codecs in Codecs.
	Codecs = map[SerializeType]codec.Codec{
		ProtoBuffer: &codec.PBCodec{},
		JSON:        &codec.JSONCodec{},
	}
)

Functions

func DecodeMessage

func DecodeMessage(s ISession, data []byte)

func ForEachMessageMeta

func ForEachMessageMeta(callback func(*MessageMeta))

ForEachMessageMeta 遍历消息元信息

func MessageFullName

func MessageFullName(rtype reflect.Type) string

MessageFullName 消息全名

func MessageNameByID

func MessageNameByID(id uint32) string

MessageNameByID 根据id查询消息名称

func RegisterMessageFunction

func RegisterMessageFunction(f MessageFunc)

RegisterMessageFunction call outside

func RegisterMessageMeta

func RegisterMessageMeta(id uint32, name string, msgType reflect.Type)

RegisterMessageMeta 注册消息元信息(代码生成专用)

func ReplyMessage

func ReplyMessage(header *Message, msg interface{}, status uint8) []byte

func RequestMessage

func RequestMessage(msg interface{}, status, serializeType uint8, indexID uint32) []byte

Types

type ISession

type ISession interface {
	GetID() int64
	SetID(int64)
	Close() bool
	Reply(header *Message, msg interface{}, status uint8) bool
	Request(msg interface{}, status, serializeType uint8, indexId uint32) bool
}

type Message

type Message struct {
	MsgId         uint32
	Index         uint32
	SerializeType uint8
	MessageType   uint8
	Status        uint8
	GateSessionId int64
	Data          []byte
}

Message tcp & webscoket share message struct

func (*Message) Decode

func (m *Message) Decode(buff []byte) error

func (*Message) Encode

func (m *Message) Encode() []byte

type MessageFunc

type MessageFunc func(session ISession, msg *Message)

type MessageMeta

type MessageMeta struct {
	Type reflect.Type
	Name string
	ID   uint32
}

func MessageMeatByID

func MessageMeatByID(id uint32) *MessageMeta

MessageMeatByID 根据id查找消息元信息

func MessageMetaByName

func MessageMetaByName(name string) *MessageMeta

MessageMetaByName 根据名字查找消息元信息

func MessageMetaByType

func MessageMetaByType(t reflect.Type) *MessageMeta

MessageMetaByType 根据类型查找消息元消息

type MessageStatusType

type MessageStatusType byte

MessageStatusType is status of messages.

const (
	// Normal is normal requests and responses.
	Normal MessageStatusType = iota
	// Error indicates some errors occur.
	Error
)

type MessageType

type MessageType byte

MessageType is message type of requests and resposnes.

const (
	// Request is message type of request
	Request MessageType = iota
	// Response is message type of response
	Response
)

type OnCloseFunc

type OnCloseFunc func(session ISession)

type OnConnectFunc

type OnConnectFunc func(session ISession)

type SerializeType

type SerializeType byte

SerializeType defines serialization type of Data.

const (
	// ProtoBuffer for payload.
	ProtoBuffer SerializeType = iota
	// JSON for payload.
	JSON
)

type SessionManager

type SessionManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSessionManager

func NewSessionManager() *SessionManager

func (*SessionManager) Add

func (sm *SessionManager) Add(session ISession)

func (*SessionManager) CloseAll

func (sm *SessionManager) CloseAll()

func (*SessionManager) Get

func (sm *SessionManager) Get(sid int64) ISession

func (*SessionManager) Len

func (sm *SessionManager) Len() int

func (*SessionManager) Remove

func (sm *SessionManager) Remove(session ISession)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL