fep

package
v0.0.0-...-13ff1a9 Latest Latest
Warning

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

Go to latest
Published: May 22, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

*

模仿netty的byteBuf,增加回溯功能
并不封装reader,由应从层调用write方法来写入.
所有的方法都不阻塞,只在routine内(actor内)使用,也不考虑routine safe的问题

Index

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
}

func (*ByteBuf) Clear

func (bf *ByteBuf) Clear()

*

彻底清空,以待重用

func (*ByteBuf) Discard

func (bf *ByteBuf) Discard()

*

清空已读数据,减少内存占用

func (*ByteBuf) MarkReadIndex

func (bf *ByteBuf) MarkReadIndex(n int)

*

在读之前标记,并回退n个字节

func (*ByteBuf) Read

func (bf *ByteBuf) Read(bs []byte) error

*

从byteBuf中读到指定slice,填不满slice会返回error
方法会清空bs,然后拷贝满bs的长度为止,否则会返回异常

func (*ByteBuf) ReadAll

func (bf *ByteBuf) ReadAll() []byte

*

读所有可读数据,若无数据可读,返回nil
直接截取内部slice,效率稍高,但存在返回值被修改的危险

func (*ByteBuf) ReadByte

func (bf *ByteBuf) ReadByte() (byte, error)

*

读一个字节,若无字节可读,返回error

func (*ByteBuf) ReadNBytes

func (bf *ByteBuf) ReadNBytes(n int) ([]byte, error)

*

同readAll

func (*ByteBuf) ResetReadIndex

func (bf *ByteBuf) ResetReadIndex(n int)

*

回到mark标记的后n个字节

func (*ByteBuf) Write

func (bf *ByteBuf) Write(bs []byte)

*

将指定slice写入buf

func (*ByteBuf) WriteNBytes

func (bf *ByteBuf) WriteNBytes(bs []byte, n int) int

*

将指定slice的前n个字节写入buf,并返回写入长度

type Frame3761

type Frame3761 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
}

Directories

Path Synopsis
*
*

Jump to

Keyboard shortcuts

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