pkt

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyPktList     = errors.New("empty pkt list")
	ErrPktCountMismatch = errors.New("pkt count mismatch")
	ErrWrongSeq         = errors.New("wrong seq number")
	ErrWrongPktSeq      = errors.New("wrong pkt seq number")

	BytesAssembler = &Assembler{}
)
View Source
var (

	// BytesDisassembler is a global disassembler for disassembling bytes slice.
	BytesDisassembler = &Disassembler{minPktLen: defaultMinPktLen}

	ErrProtocolTooLang = errors.New("protocol too lang")
)

Functions

func SetMinPktLen

func SetMinPktLen(minPktLen uint64)

SetMinPktLen will set the value of min pkt length for global bytes disassembler.

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 assembles 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 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