Documentation
¶
Overview ¶
*
模仿netty的byteBuf,增加回溯功能 并不封装reader,由应从层调用write方法来写入. 所有的方法都不阻塞,只在routine内(actor内)使用,也不考虑routine safe的问题
Index ¶
- Constants
- Variables
- func StartTcpServer(port int)
- type ByteBuf
- func (bf *ByteBuf) Clear()
- func (bf *ByteBuf) Discard()
- func (bf *ByteBuf) MarkReadIndex(n int)
- func (bf *ByteBuf) Read(bs []byte) error
- func (bf *ByteBuf) ReadAll() []byte
- func (bf *ByteBuf) ReadByte() (byte, error)
- func (bf *ByteBuf) ReadNBytes(n int) ([]byte, error)
- func (bf *ByteBuf) ResetReadIndex(n int)
- func (bf *ByteBuf) Write(bs []byte)
- func (bf *ByteBuf) WriteNBytes(bs []byte, n int) int
- type Frame3761
- type FrameContext
- type ItemConfig
- type ServerHandler
Constants ¶
View Source
const (
//worker的数量,跟netty一样,worker数是一个固定的值
WORKER_SUM = 4
)
Variables ¶
View Source
var ( NotEnoughReadable = errors.New("not enough readable bytes") ParamError = errors.New("param error") )
View Source
var Frame3761Config = [...]ItemConfig{ {"head", 1, nil, []byte{0x68}, nil, nil, false}, {"length", 4, nil, nil, func(f *Frame3761) bool { var len1 = f.itemSlice[0:2] var len2 = f.itemSlice[2:4] if bytes.Compare(len1, len2) == 0 { f.length = (int(len1[0]) + int(len1[1])*256) >> 2 return true } return false }, nil, false}, {"next68", 1, nil, []byte{0x68}, nil, nil, false}, {"control", 1, nil, nil, nil, func(f *Frame3761) { f.control = uint8(f.itemSlice[0]) }, true}, {"a1", 2, nil, nil, nil, func(f *Frame3761) { f.a1 = uint8(f.itemSlice[0])*10 + uint8(f.itemSlice[1]) }, true}, {"a2", 2, nil, nil, nil, func(f *Frame3761) { f.a2 = uint16(f.itemSlice[0])*256 + uint16(f.itemSlice[1]) }, true}, {"a3", 1, nil, nil, nil, func(f *Frame3761) { f.a3 = uint8(f.itemSlice[0]) }, true}, {"userData", 0, func(f *Frame3761) int { return f.length - 6 }, nil, nil, func(f *Frame3761) { f.usrData = append(f.usrData, f.itemSlice...) }, true}, {"cs", 1, nil, nil, func(f *Frame3761) bool { var cs1 = uint8(f.itemSlice[0]) return cs1 == f.cs }, nil, false}, {"tail", 1, nil, []byte{0x16}, nil, nil, false}, }
View Source
var ItemConfigInvalidateError = errors.New("数据项解析错误")
Functions ¶
func StartTcpServer ¶
func StartTcpServer(port int)
Types ¶
type ByteBuf ¶
type ByteBuf struct {
// contains filtered or unexported fields
}
type FrameContext ¶
type FrameContext struct { ByteBuf // contains filtered or unexported fields }
*
继承byteBuf
func (*FrameContext) ReadFrame3761 ¶
func (con *FrameContext) ReadFrame3761() (*Frame3761, error)
一个连接对应一个唯一的frameContext 应该一直调用ReadFrame3761方法,直到error不为nil(应该为notEnoughReadable)
func (*FrameContext) ReadItemConfig ¶
func (con *FrameContext) ReadItemConfig(ic *ItemConfig, f *Frame3761) error
从bf中读一个数据项,如果返回itemConfigInvalidateError,就书名解析错误
type ItemConfig ¶
type ItemConfig struct {
// contains filtered or unexported fields
}
func (*ItemConfig) Name ¶
func (ic *ItemConfig) Name() string
type ServerHandler ¶
type ServerHandler struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.