Documentation
¶
Overview ¶
Package bytex Created by xuzhuoxi on 2019-02-11. @author xuzhuoxi
Package bytex Create on 2023/6/18 @author xuzhuoxi
Package bytex Created by xuzhuoxi on 2019-02-11. @author xuzhuoxi
Package bytex Create on 2023/6/18 @author xuzhuoxi
Package bytex Created by xuzhuoxi on 2019-03-23. @author xuzhuoxi
Package bytex Created by xuzhuoxi on 2019-02-12. @author xuzhuoxi
Index ¶
- Variables
- func BigBlockHandler(in []byte) (out []byte, err error)
- func BigUnblockProcess(in []byte) (out []byte, err error)
- func DefaultBlockToDataHandler(block []byte, order binary.ByteOrder) (data []byte, length int, ok bool)
- func DefaultDataToBlockHandler(data []byte, order binary.ByteOrder) (block []byte)
- func LittleBlockHandler(in []byte) (out []byte, err error)
- func LittleUnblockProcess(in []byte) (out []byte, err error)
- func RegisterBytesProcess(t BytesHandlerType, process BytesHandler)
- type BytesHandler
- type BytesHandlerType
- type BytesProcessor
- type HandlerBlockToData
- type HandlerDataToBlock
- type IBlockToDataHandler
- type IBuffByteReader
- type IBuffByteWriter
- type IBuffDataBlock
- type IBuffDataReader
- type IBuffDataWriter
- type IBuffLen
- type IBuffReset
- type IBuffToBlock
- type IBuffToData
- type IBytesProcessor
- type IDataBlockHandler
- type IDataToBlockHandler
- type IPoolBuffDataBlock
- type IPoolBuffToBlock
- type IPoolBuffToData
Constants ¶
This section is empty.
Variables ¶
var ( DefaultPoolBuffDataBlock = NewPoolBuffDataBlock() DefaultPoolBuffToData = NewPoolBuffToData() DefaultPoolBuffToBlock = NewPoolBuffToBlock() )
var ( ErrTypeUnregister = errors.New("Type Unregister! ") ErrLittleUnblock = errors.New("LittleUnblock Error! ") ErrBigUnblock = errors.New("BigUnblock Error! ") )
var BlockSizeLen = 2
var DefaultDataBlockHandler = NewDefaultDataBlockHandler()
var DefaultOrder binary.ByteOrder = binary.BigEndian
Functions ¶
func BigBlockHandler ¶
func BigUnblockProcess ¶
func DefaultBlockToDataHandler ¶
func DefaultBlockToDataHandler(block []byte, order binary.ByteOrder) (data []byte, length int, ok bool)
DefaultBlockToDataHandler data为共享切片,非安全
func DefaultDataToBlockHandler ¶
DefaultDataToBlockHandler block是安全的
func LittleBlockHandler ¶
func LittleUnblockProcess ¶
func RegisterBytesProcess ¶
func RegisterBytesProcess(t BytesHandlerType, process BytesHandler)
Types ¶
type BytesHandlerType ¶
type BytesHandlerType int
BytesHandlerType 字节数组处理类型
const ( LittleBlock BytesHandlerType = iota + 1 LittleUnblock BigBlock BigUnblock Base64StdEncode Base64StdDecode Base64RawStdEncode Base64RawStdDecode Base64UrlEncode Base64UrlDecode Base64RawUrlEncode Base64RawUrlDecode )
type BytesProcessor ¶
type BytesProcessor struct {
// contains filtered or unexported fields
}
func (*BytesProcessor) AppendHandler ¶
func (p *BytesProcessor) AppendHandler(process BytesHandler)
func (*BytesProcessor) AppendHandlerType ¶
func (p *BytesProcessor) AppendHandlerType(t BytesHandlerType) error
func (*BytesProcessor) ClearHandlers ¶
func (p *BytesProcessor) ClearHandlers()
type HandlerBlockToData ¶
type HandlerBlockToData func(block []byte, order binary.ByteOrder) (data []byte, length int, ok bool)
HandlerBlockToData 数据数组 + Block长度 + 成功?
type HandlerDataToBlock ¶
type IBlockToDataHandler ¶
type IBlockToDataHandler interface {
// contains filtered or unexported methods
}
func NewBlockToDataHandler ¶
func NewBlockToDataHandler(order binary.ByteOrder, block2data HandlerBlockToData) IBlockToDataHandler
type IBuffByteReader ¶
type IBuffByteReader interface { io.Reader // Bytes // 缓冲中全部字节 Bytes() []byte // ReadBytes // 读取缓冲中全部字节 // 非数据安全 ReadBytes() []byte // ReadBytesTo // 读取缓冲中全部字节,并写入到dst中 ReadBytesTo(dst []byte) (n int, rs []byte) // ReadBytesCopy // 读取缓冲中全部字节 // 数据安全 ReadBytesCopy() []byte // ReadBinary // 读取一个二进制数据到out // out只支持binary.Write中支持的类型 ReadBinary(out interface{}) error }
IBuffByteReader 字节处理,不用读取长度信息
type IBuffByteWriter ¶
type IBuffByteWriter interface { io.Writer // WriteBytes // 把字节写入缓冲 WriteBytes(bytes []byte) // WriteBinary // 把in写入数据 WriteBinary(in interface{}) error }
IBuffByteWriter 字节处理,不用写入长度信息
type IBuffDataBlock ¶
type IBuffDataBlock interface { IBuffDataWriter IBuffByteReader IBuffDataReader IBuffByteWriter IBuffReset IBuffLen // contains filtered or unexported methods }
func NewBuffDataBlock ¶
func NewBuffDataBlock(handler IDataBlockHandler) IBuffDataBlock
func NewDefaultBuffDataBlock ¶
func NewDefaultBuffDataBlock() IBuffDataBlock
type IBuffDataReader ¶
type IBuffDataReader interface { io.Reader // ReadData // 读取一个Block字节数据,并拆分出数据部分返回,数据不足返回nil // 非数据安全 ReadData() []byte // ReadString // 读取一个Block字节数据,并拆分出字符串部分返回,数据不足返回nil // 非数据安全 ReadString() string // ReadDataTo // 读取一个Block字节数据,并拆分出数据部分返回,数据不足返回nil // 如果不是nil,把数据写入到dst中,返回dst写入的数据长度 ReadDataTo(dst []byte) (n int, rs []byte) // ReadDataCopy // 读取一个Block字节数据,并拆分出数据部分返回,数据不足返回nil // 数据安全 ReadDataCopy() []byte }
IBuffDataReader 数据级处理,先读取长度信息,然后再根据长度读取数据
type IBuffDataWriter ¶
type IBuffDataWriter interface { io.Writer // WriteData // 把数据包装为一个Block,写入到缓冲中,数据长度为0时不进行处理 WriteData(bytes []byte) // WriteString // 把字符串装为一个Block,写入到缓冲中,数据长度为0时不进行处理 WriteString(str string) }
IBuffDataWriter 数据级处理,先写入长度信息,然后再写入数据
type IBuffReset ¶
type IBuffReset interface { // Reset // 清空缓冲区 Reset() }
type IBuffToBlock ¶
type IBuffToBlock interface { IBuffByteReader IBuffDataWriter IBuffReset IBuffLen // contains filtered or unexported methods }
func NewBuffToBlock ¶
func NewBuffToBlock(handler IDataBlockHandler) IBuffToBlock
func NewDefaultBuffToBlock ¶
func NewDefaultBuffToBlock() IBuffToBlock
type IBuffToData ¶
type IBuffToData interface { IBuffDataReader IBuffByteWriter IBuffReset IBuffLen // contains filtered or unexported methods }
func NewBuffToData ¶
func NewBuffToData(handler IDataBlockHandler) IBuffToData
func NewDefaultBuffToData ¶
func NewDefaultBuffToData() IBuffToData
type IBytesProcessor ¶
type IBytesProcessor interface { // AppendHandler // 追加处理函数 AppendHandler(process BytesHandler) // AppendHandlerType // 追加处理类型 AppendHandlerType(t BytesHandlerType) error // ClearHandlers // 清除全部处理 ClearHandlers() // Handle // 数据处理 Handle(in []byte) (out []byte, errIdx int, err error) }
IBytesProcessor 字节数组处理器
type IDataBlockHandler ¶
type IDataBlockHandler interface {
// contains filtered or unexported methods
}
func NewDataBlockHandler ¶
func NewDataBlockHandler(order binary.ByteOrder, data2block HandlerDataToBlock, block2data HandlerBlockToData) IDataBlockHandler
func NewDefaultDataBlockHandler ¶
func NewDefaultDataBlockHandler() IDataBlockHandler
type IDataToBlockHandler ¶
type IDataToBlockHandler interface {
// contains filtered or unexported methods
}
func NewDataToBlockHandler ¶
func NewDataToBlockHandler(order binary.ByteOrder, data2block HandlerDataToBlock) IDataToBlockHandler
type IPoolBuffDataBlock ¶
type IPoolBuffDataBlock interface { Register(newFunc func() IBuffDataBlock) GetInstance() IBuffDataBlock Recycle(instance IBuffDataBlock) bool }
func NewPoolBuffDataBlock ¶
func NewPoolBuffDataBlock() IPoolBuffDataBlock
type IPoolBuffToBlock ¶
type IPoolBuffToBlock interface { Register(newFunc func() IBuffToBlock) GetInstance() IBuffToBlock Recycle(instance IBuffToBlock) bool }
func NewPoolBuffToBlock ¶
func NewPoolBuffToBlock() IPoolBuffToBlock
type IPoolBuffToData ¶
type IPoolBuffToData interface { Register(newFunc func() IBuffToData) GetInstance() IBuffToData Recycle(instance IBuffToData) bool }
func NewPoolBuffToData ¶
func NewPoolBuffToData() IPoolBuffToData