protocol

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseIDsToStrings

func ParseIDsToStrings(pids []ID) []string

ParseIDsToStrings parses ID slice to string slice.

Types

type DataPackage

type DataPackage struct {
	Protocol string
	Payload  []byte
	Compress bool
}

DataPackage .

func (*DataPackage) Marshal

func (d *DataPackage) Marshal(buf []byte) ([]byte, error)

Marshal .

func (*DataPackage) Size

func (d *DataPackage) Size() (s uint64)

Size .

func (*DataPackage) Unmarshal

func (d *DataPackage) Unmarshal(buf []byte) (uint64, error)

Unmarshal .

type ID

type ID string

ID is an identifier used to mark the module which the net msg belong to.

const (
	// TestingPID is a protocol id for testing.
	TestingPID ID = "/_testing"
)

func ParseStringsToIDs

func ParseStringsToIDs(strs []string) []ID

ParseStringsToIDs parses string slice to ID slice.

type Package

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

Package is a container for net message.

func NewPackage

func NewPackage(id ID, payload []byte) *Package

NewPackage create a Package contains message payload with protocol.

func (*Package) FromBytes

func (m *Package) FromBytes(data []byte) error

FromBytes parse bytes received from receive stream into Package.

func (*Package) Payload

func (m *Package) Payload() []byte

Payload return the message payload bytes.

func (*Package) ProtocolID

func (m *Package) ProtocolID() ID

ProtocolID return the protocol id that the message marked.

func (*Package) ToBytes

func (m *Package) ToBytes(enableCompress bool) ([]byte, error)

ToBytes parse Package to bytes for sending on stream finally.

Jump to

Keyboard shortcuts

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