stream

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithPacketProcessor

func WithPacketProcessor(pp PacketProcessor) func(s *SessionCtx)

func WithReact

func WithReact() func(s *SessionCtx)

Types

type HeaderTailPacketProcessor

type HeaderTailPacketProcessor struct {
	// contains filtered or unexported fields
}

HeaderTailPacketProcessor 固定包头包尾分包器

func (*HeaderTailPacketProcessor) Data

func (spp *HeaderTailPacketProcessor) Data(data []byte) (n int)

func (*HeaderTailPacketProcessor) Listen

func (spp *HeaderTailPacketProcessor) Listen(onPacket func(p []byte))

type Option

type Option func(s *SessionCtx)

type PacketProcessor

type PacketProcessor interface {
	Listen(onPacket func(p []byte))
	Data(data []byte) (n int)
}

func NewHeadTailPP

func NewHeadTailPP(head []byte, tail []byte) (pp PacketProcessor)

func NewSplitPP

func NewSplitPP(split byte) (pp PacketProcessor)

type Session

type Session interface {
	OnData(p []byte, size int, err error)
	Read(p []byte) (size int, err error)
	Write(p []byte) (size int, err error)
}

func NewSerialSession

func NewSerialSession(ctx context.Context, name string, baud int, opts ...Option) (s Session, err error)

func NewSession

func NewSession(ctx context.Context, rwc io.ReadWriter, opts ...Option) (s Session)

type SessionCtx

type SessionCtx struct {
	// contains filtered or unexported fields
}

func (*SessionCtx) Close added in v1.16.0

func (s *SessionCtx) Close()

func (*SessionCtx) OnData

func (s *SessionCtx) OnData(p []byte, size int, err error)

func (*SessionCtx) Read

func (s *SessionCtx) Read(p []byte) (size int, err error)

func (*SessionCtx) Write

func (s *SessionCtx) Write(p []byte) (size int, err error)

type SplitPacketProcessor

type SplitPacketProcessor struct {
	// contains filtered or unexported fields
}

SplitPacketProcessor 分隔符分包器, 每个包用Split标记结尾

func (*SplitPacketProcessor) Data

func (spp *SplitPacketProcessor) Data(data []byte) (n int)

func (*SplitPacketProcessor) Listen

func (spp *SplitPacketProcessor) Listen(onPacket func(p []byte))

Jump to

Keyboard shortcuts

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