pkt

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
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{}
)
View Source
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

func SetMinPktLen

func SetMinPktLen(minPktLen uint64)

SetMinPktLen . @Description: will set the value of min pkt length for global bytes disassembler. @param minPktLen:

Types

type Assembler

type Assembler struct {
}

Assembler provides a function assemble some Pkt instances which disassembled to a slice of bytes.

func (*Assembler) AssembleBytes

func (a *Assembler) AssembleBytes(pktList []*Pkt) (bytes, protocol []byte, err error)

AssembleBytes . @Description: assembles some Pkt instances which disassembled to a slice of bytes. @receiver a @param pktList: @return bytes: @return protocol: @return err:

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 NewPktCache

func NewPktCache() *Cache

NewPktCache create a new Cache instance.

func (*Cache) Close

func (c *Cache) Close()

Close the cache.

func (*Cache) FullPktC

func (c *Cache) FullPktC() <-chan *FullPktResult

FullPktC return the fullPktNotifyC of Cache.

func (*Cache) PutPkt

func (c *Cache) PutPkt(sender string, pkt *Pkt) bool

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.

func (*Cache) Run

func (c *Cache) Run()

Run a goroutine for checking expire Pkt.

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

type FullPktResult struct {
	Sender  string
	PktList []*Pkt
}

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.

func (*Pkt) Marshal

func (p *Pkt) Marshal() []byte

Marshal a Pkt to a slice of bytes.

func (*Pkt) Seq

func (p *Pkt) Seq() uint64

Seq of the msg that Pkt belong to.

func (*Pkt) Unmarshal

func (p *Pkt) Unmarshal(payload []byte) error

Unmarshal a slice of bytes to a Pkt.

Jump to

Keyboard shortcuts

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