packet

package
v0.0.0-...-9ccd474 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: BSD-3-Clause Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Alignment = 8

	// Packet header
	OffsetSize   = 0
	OffsetCode   = 4
	OffsetDomain = 6
	OffsetIndex  = 7
	HeaderSize   = 8

	// Services packet header
	OffsetServicesCount = HeaderSize + 0
	ServicesHeaderSize  = HeaderSize + 2

	// Flow packet header
	FlowHeaderSize = HeaderSize

	// Data packet header
	OffsetDataID   = HeaderSize + 0
	OffsetDataNote = HeaderSize + 4
	DataHeaderSize = HeaderSize + 8
)

Variables

This section is empty.

Functions

func Align

func Align(length int) int

Align packet length up to a multiple of packet alignment.

func IsValidCall

func IsValidCall(b []byte, c Code) bool

IsValidCall checks service call packet's or call result packet's header. Packet content is disregarded.

func IsValidData

func IsValidData(b []byte, c Code) bool

IsValidData checks stream data packet's header. Data is disregarded.

func IsValidFlow

func IsValidFlow(b []byte, c Code) bool

IsValidFlow checks stream flow packet, including the flow entries.

func IsValidInfo

func IsValidInfo(b []byte, c Code) bool

IsValidInfo checks service info packet's header. Packet content is disregarded.

Types

type Buf

type Buf []byte

Buf holds a packet of at least HeaderSize bytes.

func ImportCall

func ImportCall(b []byte, c Code) (p Buf, err error)

ImportCall packet, validating it leniently. The buffer is NOT copied.

func Make

func Make(code Code, domain Domain, packetSize int) Buf

func MakeCall

func MakeCall(code Code, contentSize int) Buf

func MakeDataEOF

func MakeDataEOF(code Code, id int32) Buf

func MakeFlow

func MakeFlow(code Code, id, increment int32) Buf

func MakeFlowEOF

func MakeFlowEOF(code Code, id int32) Buf

func MakeInfo

func MakeInfo(code Code, contentSize int) Buf

func MustBeCall

func MustBeCall(b Buf) Buf

MustBeCall panicks if b is not in the call domain. The value is passed through.

func MustBeInfo

func MustBeInfo(b Buf) Buf

MustBeInfo panicks if b is not in the info domain. The value is passed through.

func (Buf) Code

func (b Buf) Code() Code

func (Buf) Content

func (b Buf) Content() []byte

Content of a received packet, or buffer for initializing sent packet.

func (Buf) Cut

func (b Buf) Cut(headerSize, prefixLen int) (prefix, unused Buf)

Cut a packet into two parts. The headerSize parameter determins how many bytes are initialized in the second part: the header is copied from the first part. The length of the first part is given as the prefixLen parameter. If the buffer is too short for the second part, the length of the second buffer will be zero.

func (Buf) Domain

func (b Buf) Domain() Domain

func (Buf) EncodedSize

func (b Buf) EncodedSize() int

EncodedSize decodes the packet header field.

func (Buf) Index

func (b Buf) Index() uint8

func (Buf) SetCode

func (b Buf) SetCode(code Code)

func (Buf) SetIndex

func (b Buf) SetIndex(i uint8)

func (Buf) SetSize

func (b Buf) SetSize()

SetSize encodes the current slice length into the packet header.

func (Buf) String

func (b Buf) String() (s string)

func (Buf) Thunk

func (b Buf) Thunk() Thunk

Thunk returns a function which returns the packet.

type Code

type Code int16

Code represents the source or destination of a packet. It is specific to a program instance.

const (
	CodeServices Code = -1
)

func (Code) String

func (code Code) String() string

type DataBuf

type DataBuf Buf

DataBuf holds a data packet of at least DataHeaderSize bytes.

func ImportData

func ImportData(b []byte, c Code) (p DataBuf, err error)

ImportData packet, validating it leniently. The buffer is NOT copied.

func MakeData

func MakeData(code Code, id int32, dataSize int) DataBuf

func MustBeData

func MustBeData(b Buf) DataBuf

MustBeData panicks if b is not in the data domain. The value is passed through.

func (DataBuf) Code

func (b DataBuf) Code() Code

func (DataBuf) Cut

func (b DataBuf) Cut(dataLen int) (prefix Buf, unused DataBuf)

func (DataBuf) Data

func (b DataBuf) Data() []byte

func (DataBuf) DataLen

func (b DataBuf) DataLen() int

func (DataBuf) EOF

func (b DataBuf) EOF() bool

func (DataBuf) ID

func (b DataBuf) ID() int32

func (DataBuf) Note

func (b DataBuf) Note() int32

Note is a value associated with a data packet. Each service interface specifies its semantics separately.

func (DataBuf) SetNote

func (b DataBuf) SetNote(value int32)

SetNote value. It defaults to zero.

func (DataBuf) String

func (b DataBuf) String() string

func (DataBuf) Thunk

func (b DataBuf) Thunk() Thunk

Thunk returns a function which returns the packet.

type Domain

type Domain uint8
const (
	DomainCall Domain = iota
	DomainInfo
	DomainFlow
	DomainData
)

func (Domain) String

func (dom Domain) String() string

type FlowBuf

type FlowBuf Buf

FlowBuf holds a flow packet of at least FlowHeaderSize bytes.

func MakeFlows

func MakeFlows(code Code, count int) FlowBuf

func MustBeFlow

func MustBeFlow(b Buf) FlowBuf

MustBeFlow panicks if b is not in the flow domain. The value is passed through.

func (FlowBuf) Code

func (b FlowBuf) Code() Code

func (FlowBuf) Get

func (b FlowBuf) Get(i int) (id, increment int32)

func (FlowBuf) Num

func (b FlowBuf) Num() int

func (FlowBuf) Set

func (b FlowBuf) Set(i int, id, increment int32)

func (FlowBuf) String

func (b FlowBuf) String() string

func (FlowBuf) Thunk

func (b FlowBuf) Thunk() Thunk

Thunk returns a function which returns the packet.

type Service

type Service struct {
	MaxSendSize int // Maximum size which the program is prepared to receive.
	Code        Code
}

Service packet properties.

type Thunk

type Thunk func() (Buf, error)

Thunk may be called once to acquire a packet. It returns an empty buffer if no packet was available after all.

Directories

Path Synopsis
Package packetio provides streaming utilities.
Package packetio provides streaming utilities.

Jump to

Keyboard shortcuts

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