protocol

package
v0.0.0-...-d151d1d Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownCompressType is returned when encountering an unknown compress type.
	ErrUnknownCompressType = errors.New("unknown compress type")

	// ErrInvalidDataLength is returned when the data length is invalid.
	ErrInvalidDataLength = errors.New("invalid data length")
)

Functions

func ParseProtocolIDsToStrings

func ParseProtocolIDsToStrings(pids []ID) []string

ParseProtocolIDsToStrings converts a ID slice to a string slice.

Types

type CompressType

type CompressType uint8

CompressType represents the type of compression used for payload.

const (
	CompressTypeNone CompressType = iota // No compression
	CompressTypeGzip                     // Gzip compression
)

type ID

type ID string

ID is an identifier used to mark the module to which the network message belongs.

const (
	// TestingProtocolID is a protocol ID for testing purposes.
	TestingProtocolID ID = "/_testing"
)

func ParseStringsToProtocolIDs

func ParseStringsToProtocolIDs(strs []string) []ID

ParseStringsToProtocolIDs converts a string slice to a ID slice.

func (ID) String

func (i ID) String() string

type PayloadPackage

type PayloadPackage interface {
	ProtocolID() ID           // Returns the protocol ID.
	Payload() []byte          // Returns the payload data.
	Marshal() ([]byte, error) // Marshals the payload package into a byte slice.
	Unmarshal([]byte) error   // Unmarshals the byte slice into the payload package.
}

PayloadPackage represents a protocol payload package.

func NewPayloadPackage

func NewPayloadPackage(protocol ID, payload []byte, compressType CompressType) PayloadPackage

type PayloadPkg

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

PayloadPkg represents a protocol payload package.

func (*PayloadPkg) Marshal

func (p *PayloadPkg) Marshal() (bz []byte, err error)

Marshal marshals the payload package into a byte slice.

func (*PayloadPkg) Payload

func (p *PayloadPkg) Payload() []byte

Payload returns the payload data of the payload package.

func (*PayloadPkg) ProtocolID

func (p *PayloadPkg) ProtocolID() ID

ProtocolID returns the protocol ID of the payload package.

func (*PayloadPkg) Unmarshal

func (p *PayloadPkg) Unmarshal(bz []byte) (err error)

Unmarshal unmarshals the byte slice into the payload package.

Jump to

Keyboard shortcuts

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