Documentation ¶
Overview ¶
conn 封装过的连接 可以直接读出帧
帧分成三个部分 分别是len、opcode、payload
len是payload的长度 有baseLen和extendLen两种 如果len小于255 占一个byte 如果length的长度大于等于255 先1byte的255 然后用2byte来表示长度 最大2byte
opcode占1个byte 具体有哪些看下面的常量
不管payload是什么类型的数据 这里只处理读写数据
Index ¶
- Constants
- type Conn
- type DefaultConn
- func (c *DefaultConn) Addr() (res string)
- func (c *DefaultConn) Close() error
- func (c *DefaultConn) ReadData() (opcode uint8, data []byte, err error)
- func (c *DefaultConn) WriteData(opcode int, in interface{}) (err error)
- func (c *DefaultConn) WriteError(data interface{}) (err error)
- func (c *DefaultConn) WriteRequest(data interface{}) (err error)
- func (c *DefaultConn) WriteResponse(data interface{}) (err error)
- func (c *DefaultConn) WriteSign(data interface{}) (err error)
Constants ¶
View Source
const ( // 第一个length的最大值 BaseLenMax = 255 // 上述变量的byte BaseLenMaxByte = byte(BaseLenMax) // length的最大值 ExtendLenMax = 255 * 255 // opcode // 注册服务 OpSign = 1 // 请求 OpRequest = 2 // 响应 OpResponse = 3 // 错误 OpError = 4 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface { ReadData() (opcode uint8, data []byte, err error) WriteSign(interface{}) error WriteRequest(interface{}) error WriteResponse(interface{}) error WriteError(interface{}) error Close() error Addr() string // contains filtered or unexported methods }
Conn 封装的tcp连接的接口 现在实现的是一个普通的连接 后面或许会上连接池
type DefaultConn ¶
type DefaultConn struct {
// contains filtered or unexported fields
}
DefaultConn 默认的不带连接池的连接
func (*DefaultConn) ReadData ¶
func (c *DefaultConn) ReadData() (opcode uint8, data []byte, err error)
ReadData 读一个包 返回opcode和json数据
func (*DefaultConn) WriteData ¶
func (c *DefaultConn) WriteData(opcode int, in interface{}) (err error)
WriteData 写数据进去
func (*DefaultConn) WriteError ¶
func (c *DefaultConn) WriteError(data interface{}) (err error)
WriteError 写一个错误帧
func (*DefaultConn) WriteRequest ¶
func (c *DefaultConn) WriteRequest(data interface{}) (err error)
WriteRequest 写一个请求帧
func (*DefaultConn) WriteResponse ¶
func (c *DefaultConn) WriteResponse(data interface{}) (err error)
WriteResponse 写一个响应帧
func (*DefaultConn) WriteSign ¶
func (c *DefaultConn) WriteSign(data interface{}) (err error)
WriteSign 写一个注册帧
Click to show internal directories.
Click to hide internal directories.