messages

package
v0.0.0-...-b45fe33 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Handler types.HandlerType // The handler type (1 byte)
	Key     [32]byte          // Fixed 32-byte key (e.g., Ethereum hash)
	Data    []byte            // The remaining data after the key
}

Message struct represents a UDP message

func Decode

func Decode(data []byte) (*Message, error)

Decode decodes a byte slice into a Message struct without allocating new memory for data.

func GenerateRandomMessage

func GenerateRandomMessage(handler types.HandlerType) (*Message, error)

GenerateRandomMessage generates a Message with a random handler and key, and no data.

func GenerateRandomMessageWithData

func GenerateRandomMessageWithData(handler types.HandlerType, data []byte) (*Message, error)

GenerateRandomMessageWithData generates a Message with a key, and a specified data payload.

func (*Message) Encode

func (m *Message) Encode() ([]byte, error)

Encode encodes the Message struct into a byte slice. This method allocates a new buffer for every call, unlike EncodeWithBuffer which reuses a buffer.

func (*Message) EncodeWithBuffer

func (m *Message) EncodeWithBuffer(buf []byte) ([]byte, error)

EncodeWithBuffer encodes the Message struct into a provided byte slice (buffer). Assumes the buffer is large enough and avoids allocating new buffers. Designed to be used with sync.Pool

Jump to

Keyboard shortcuts

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