Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyPktList the error if the pkt list is empty ErrEmptyPktList = errors.New("empty pkt list") // ErrPktCountMismatch the error of the pkt count mismatch ErrPktCountMismatch = errors.New("pkt count mismatch") // ErrWrongSeq the error of the seq number is wrong ErrWrongSeq = errors.New("wrong seq number") // ErrWrongPktSeq he error of the pkt seq number is wrong ErrWrongPktSeq = errors.New("wrong pkt seq number") // BytesAssembler . BytesAssembler = &Assembler{} )
var ( // BytesDisassembler is a global disassembler for disassembling bytes slice. BytesDisassembler = &Disassembler{minPktLen: defaultMinPktLen} // ErrProtocolTooLang the error of the protocol id is too lang ErrProtocolTooLang = errors.New("protocol too lang") )
Functions ¶
Types ¶
type Assembler ¶
type Assembler struct { }
Assembler provides a function assemble some Pkt instances which disassembled to a slice of bytes.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache for collecting Pkt of payloads. If all Pkt belong to the same payload collecting finished, a FullPktResult contains sender id string and all Pkt list will be push to fullPktNotifyC.
func (*Cache) FullPktC ¶
func (c *Cache) FullPktC() <-chan *FullPktResult
FullPktC return the fullPktNotifyC of Cache.
func (*Cache) PutPkt ¶
PutPkt put a Pkt into cache. If all Pkt of a msg payload collected, a FullPktResult contains sender id string and all Pkt list will be push to fullPktNotifyC.
type Disassembler ¶
type Disassembler struct {
// contains filtered or unexported fields
}
Disassembler provides a function that can disassemble a slice of bytes to some Pkt instances.
func (*Disassembler) DisassembleBytes ¶
func (d *Disassembler) DisassembleBytes(bytes []byte, protocol []byte) ([]*Pkt, error)
DisassembleBytes disassembles bytes slice to some Pkt instances. The length of protocol given must not be greater than 255. If success, The max size of Pkt list will not be greater than 256.
type FullPktResult ¶
FullPktResult wraps the sender string and the Pkt list of a msg payload whose seq is the same value.
type Pkt ¶
type Pkt struct {
// contains filtered or unexported fields
}
Pkt is a unit packet for bytes assembler/disassembler. A slice of bytes can be disassembled to a number of Pkt. A number of Pkt can be assembled to a slice of bytes.