Documentation ¶
Index ¶
- Variables
- func ConnectTCP(host string, port int) (net.Conn, error)
- func IsConnectionError(_err interface{}) bool
- func PackFloat32(order binary.ByteOrder, b []byte, f float32)
- func PutFloat32(b []byte, f float32)
- func ServeTCP(listenAddr string, delegate TCPServerDelegate) error
- func ServeTCPForever(listenAddr string, delegate TCPServerDelegate)
- func UnpackFloat32(order binary.ByteOrder, b []byte) (f float32)
- type BufferedConnection
- type Connection
- type GobMsgPacker
- type JSONMsgPacker
- type JsoniterMsgPacker
- type MessagePackMsgPacker
- type MsgPacker
- type NetConnection
- type Packet
- func (p *Packet) AddRefCount(add int64)
- func (p *Packet) AppendArgs(args []interface{})
- func (p *Packet) AppendBool(b bool)
- func (p *Packet) AppendByte(b byte)
- func (p *Packet) AppendBytes(v []byte)
- func (p *Packet) AppendClientID(id common.ClientID)
- func (p *Packet) AppendData(msg interface{})
- func (p *Packet) AppendEntityID(id common.EntityID)
- func (p *Packet) AppendFloat32(f float32)
- func (p *Packet) AppendFloat64(f float64)
- func (p *Packet) AppendStringList(list []string)
- func (p *Packet) AppendUint16(v uint16)
- func (p *Packet) AppendUint32(v uint32)
- func (p *Packet) AppendUint64(v uint64)
- func (p *Packet) AppendVarBytes(v []byte)
- func (p *Packet) AppendVarStr(s string)
- func (p *Packet) AssureCapacity(need uint32)
- func (p *Packet) ClearPayload()
- func (p *Packet) GetPayloadLen() uint32
- func (p *Packet) HasUnreadPayload() bool
- func (p *Packet) Payload() []byte
- func (p *Packet) PayloadCap() uint32
- func (p *Packet) PopUint32() (v uint32)
- func (p *Packet) ReadArgs() [][]byte
- func (p *Packet) ReadBool() (v bool)
- func (p *Packet) ReadBytes(size uint32) []byte
- func (p *Packet) ReadClientID() common.ClientID
- func (p *Packet) ReadData(msg interface{})
- func (p *Packet) ReadEntityID() common.EntityID
- func (p *Packet) ReadFloat32() float32
- func (p *Packet) ReadFloat64() float64
- func (p *Packet) ReadOneByte() (v byte)
- func (p *Packet) ReadStringList() []string
- func (p *Packet) ReadUint16() (v uint16)
- func (p *Packet) ReadUint32() (v uint32)
- func (p *Packet) ReadUint64() (v uint64)
- func (p *Packet) ReadVarBytes() []byte
- func (p *Packet) ReadVarStr() string
- func (p *Packet) Release()
- func (p *Packet) SetNotCompress()
- func (p *Packet) SetPayloadLen(plen uint32)
- func (p *Packet) TotalPayload() []byte
- func (p *Packet) UnreadPayload() []byte
- func (p *Packet) UnwrittenPayload() []byte
- type PacketConnection
- func (pc *PacketConnection) Close() error
- func (pc *PacketConnection) Flush(reason string) (err error)
- func (pc *PacketConnection) LocalAddr() net.Addr
- func (pc *PacketConnection) NewPacket() *Packet
- func (pc *PacketConnection) RecvPacket() (*Packet, error)
- func (pc *PacketConnection) RemoteAddr() net.Addr
- func (pc *PacketConnection) SendPacket(packet *Packet) error
- func (pc *PacketConnection) SetRecvDeadline(deadline time.Time) error
- func (pc *PacketConnection) String() string
- type TCPServerDelegate
Constants ¶
This section is empty.
Variables ¶
var ( // NETWORK_ENDIAN is the network Endian of connections NETWORK_ENDIAN = binary.LittleEndian )
Functions ¶
func ConnectTCP ¶
ConnectTCP connects to host:port in TCP
func IsConnectionError ¶
func IsConnectionError(_err interface{}) bool
IsConnectionError check if the error is a connection error (close)
func PackFloat32 ¶
PackFloat32 packs float32 in specified byte order
func PutFloat32 ¶
func ServeTCP ¶
func ServeTCP(listenAddr string, delegate TCPServerDelegate) error
ServeTCP serves on specified address as TCP server
func ServeTCPForever ¶
func ServeTCPForever(listenAddr string, delegate TCPServerDelegate)
ServeTCPForever serves on specified address as TCP server, for ever ...
Types ¶
type BufferedConnection ¶
type BufferedConnection struct { Connection // contains filtered or unexported fields }
BufferedConnection provides buffered write to connections
func NewBufferedConnection ¶
func NewBufferedConnection(conn Connection) *BufferedConnection
NewBufferedWriteConnection creates a new connection with buffered write based on underlying connection
func (*BufferedConnection) Flush ¶
func (brc *BufferedConnection) Flush() error
type Connection ¶
Connection interface for connections to servers
type GobMsgPacker ¶
type GobMsgPacker struct{}
GobMsgPacker packs and unpacks message in golang's Gob format
func (GobMsgPacker) PackMsg ¶
func (mp GobMsgPacker) PackMsg(msg interface{}, buf []byte) ([]byte, error)
PackMsg packs a message to bytes of gob format
func (GobMsgPacker) UnpackMsg ¶
func (mp GobMsgPacker) UnpackMsg(data []byte, msg interface{}) error
UnpackMsg unpacks bytes of gob format to message
type JSONMsgPacker ¶
type JSONMsgPacker struct{}
JsoniterMsgPacker packs and unpacks messages in JSON format
func (JSONMsgPacker) PackMsg ¶
func (mp JSONMsgPacker) PackMsg(msg interface{}, buf []byte) ([]byte, error)
PackMsg packs message to bytes of JSON format
func (JSONMsgPacker) UnpackMsg ¶
func (mp JSONMsgPacker) UnpackMsg(data []byte, msg interface{}) error
UnpackMsg unpacks bytes of JSON format to message
type JsoniterMsgPacker ¶
type JsoniterMsgPacker struct{}
JsoniterMsgPacker packs and unpacks messages in JSON format
func (JsoniterMsgPacker) PackMsg ¶
func (mp JsoniterMsgPacker) PackMsg(msg interface{}, buf []byte) ([]byte, error)
PackMsg packs message to bytes of JSON format
func (JsoniterMsgPacker) UnpackMsg ¶
func (mp JsoniterMsgPacker) UnpackMsg(data []byte, msg interface{}) error
UnpackMsg unpacks bytes of JSON format to message
type MessagePackMsgPacker ¶
type MessagePackMsgPacker struct{}
MessagePackMsgPacker packs and unpacks message in MessagePack format
func (MessagePackMsgPacker) PackMsg ¶
func (mp MessagePackMsgPacker) PackMsg(msg interface{}, buf []byte) ([]byte, error)
PackMsg packs message to bytes in MessagePack format
func (MessagePackMsgPacker) UnpackMsg ¶
func (mp MessagePackMsgPacker) UnpackMsg(data []byte, msg interface{}) error
UnpackMsg unpacksbytes in MessagePack format to message
type MsgPacker ¶
type MsgPacker interface { PackMsg(msg interface{}, buf []byte) ([]byte, error) UnpackMsg(data []byte, msg interface{}) error }
MsgPacker is used to packs and unpacks messages
var ( // MSG_PACKER is used for packing and unpacking network data MSG_PACKER MsgPacker = MessagePackMsgPacker{} )
type NetConnection ¶
NetConnection converts net.Conn to Connection
type Packet ¶
type Packet struct {
// contains filtered or unexported fields
}
Packet is a packet for sending data
func (*Packet) AddRefCount ¶
AddRefCount adds reference count of packet
func (*Packet) AppendArgs ¶
func (p *Packet) AppendArgs(args []interface{})
AppendArgs appends arguments to the end of payload one by one
func (*Packet) AppendBool ¶
AppendBool appends one byte 1/0 to the end of payload
func (*Packet) AppendByte ¶
AppendByte appends one byte to the end of payload
func (*Packet) AppendBytes ¶
AppendBytes appends slice of bytes to the end of payload
func (*Packet) AppendClientID ¶
AppendClientID appends one Client ID to the end of payload
func (*Packet) AppendData ¶
func (p *Packet) AppendData(msg interface{})
AppendData appends one data of any type to the end of payload
func (*Packet) AppendEntityID ¶
AppendEntityID appends one Entity ID to the end of payload
func (*Packet) AppendFloat32 ¶
AppendFloat32 appends one float32 to the end of payload
func (*Packet) AppendFloat64 ¶
AppendFloat64 appends one float64 to the end of payload
func (*Packet) AppendStringList ¶
AppendStringList appends a list of strings to the end of payload
func (*Packet) AppendUint16 ¶
AppendUint16 appends one uint16 to the end of payload
func (*Packet) AppendUint32 ¶
AppendUint32 appends one uint32 to the end of payload
func (*Packet) AppendUint64 ¶
AppendUint64 appends one uint64 to the end of payload
func (*Packet) AppendVarBytes ¶
AppendVarBytes appends varsize bytes to the end of payload
func (*Packet) AppendVarStr ¶
AppendVarStr appends a varsize string to the end of payload
func (*Packet) AssureCapacity ¶
func (*Packet) GetPayloadLen ¶
GetPayloadLen returns the payload length
func (*Packet) HasUnreadPayload ¶
HasUnreadPayload returns if all payload is read
func (*Packet) PayloadCap ¶
PayloadCap returns the current payload capacity
func (*Packet) ReadClientID ¶
ReadClientID reads one ClientID from the beginning of unread payload
func (*Packet) ReadData ¶
func (p *Packet) ReadData(msg interface{})
ReadData reads one data of any type from the beginning of unread payload
func (*Packet) ReadEntityID ¶
ReadEntityID reads one EntityID from the beginning of unread payload
func (*Packet) ReadFloat32 ¶
ReadFloat32 reads one float32 from the beginning of unread payload
func (*Packet) ReadFloat64 ¶
ReadFloat64 reads one float64 from the beginning of unread payload
func (*Packet) ReadOneByte ¶
ReadOneByte reads one byte from the beginning
func (*Packet) ReadStringList ¶
ReadStringList reads a list of strings from the beginning of unread payload
func (*Packet) ReadUint16 ¶
ReadUint16 reads one uint16 from the beginning of unread payload
func (*Packet) ReadUint32 ¶
ReadUint32 reads one uint32 from the beginning of unread payload
func (*Packet) ReadUint64 ¶
ReadUint64 reads one uint64 from the beginning of unread payload
func (*Packet) ReadVarBytes ¶
ReadVarBytes reads a varsize slice of bytes from the beginning of unread payload
func (*Packet) ReadVarStr ¶
ReadVarStr reads a varsize string from the beginning of unread payload
func (*Packet) SetNotCompress ¶
func (p *Packet) SetNotCompress()
SetNotCompress force the packet not to be compressed
func (*Packet) SetPayloadLen ¶
SetPayloadLen sets the payload l
func (*Packet) TotalPayload ¶
func (*Packet) UnreadPayload ¶
UnreadPayload returns the unread payload
func (*Packet) UnwrittenPayload ¶
UnwrittenPayload returns the unwritten payload, which is the left payload capacity
type PacketConnection ¶
type PacketConnection struct {
// contains filtered or unexported fields
}
PacketConnection is a connection that send and receive data packets upon a network stream connection
func NewPacketConnection ¶
func NewPacketConnection(conn Connection, compressor compress.Compressor) *PacketConnection
NewPacketConnection creates a packet connection based on network connection
func (*PacketConnection) Flush ¶
func (pc *PacketConnection) Flush(reason string) (err error)
Flush connection writes
func (*PacketConnection) LocalAddr ¶
func (pc *PacketConnection) LocalAddr() net.Addr
LocalAddr returns the local address
func (*PacketConnection) NewPacket ¶
func (pc *PacketConnection) NewPacket() *Packet
NewPacket allocates a new packet (usually for sending)
func (*PacketConnection) RecvPacket ¶
func (pc *PacketConnection) RecvPacket() (*Packet, error)
RecvPacket receives the next packet
func (*PacketConnection) RemoteAddr ¶
func (pc *PacketConnection) RemoteAddr() net.Addr
RemoteAddr return the remote address
func (*PacketConnection) SendPacket ¶
func (pc *PacketConnection) SendPacket(packet *Packet) error
SendPacket send packets to remote
func (*PacketConnection) SetRecvDeadline ¶
func (pc *PacketConnection) SetRecvDeadline(deadline time.Time) error
SetRecvDeadline sets the receive deadline
func (*PacketConnection) String ¶
func (pc *PacketConnection) String() string
type TCPServerDelegate ¶
TCPServerDelegate is the implementations that a TCP server should provide