msg

package
v0.0.0-...-49870ec Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package msg provides utilities for constructing, sending and receiving binary messages with fixed-size headers and variable payloads.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

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

Message represents a single structured message with a fixed header and a payload.

func New

func New(w io.Writer) (*Message, error)

New creates a new Message associated with the given writer. It automatically generates a random message ID and sets the current timestamp.

func Rcv

func Rcv(r io.Reader) (*Message, error)

Rcv reads a message header from the given reader and returns a new Message.

func (*Message) ID

func (m *Message) ID() [16]byte

ID returns the message ID.

func (*Message) Len

func (m *Message) Len() int

Len returns the payload length from the header.

func (*Message) Read

func (m *Message) Read() iter.Seq2[[]byte, error]

Read returns an iterator that yields payload chunks and errors while reading.

func (*Message) ReadFull

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

ReadFull reads the entire message and returns it as a single byte slice.

func (*Message) SetToken

func (m *Message) SetToken(tok [16]byte)

SetToken sets the message token.

func (*Message) SetType

func (m *Message) SetType(typ Type)

SetType sets the message type.

func (*Message) Timestamp

func (m *Message) Timestamp() time.Time

Timestamp returns the message timestamp as a time.Time value.

func (*Message) Token

func (m *Message) Token() [16]byte

Token returns the message token.

func (*Message) Type

func (m *Message) Type() Type

Type returns the message type.

func (*Message) Write

func (m *Message) Write(pld []byte) (int, error)

Write writes the message header and payload to the associated writer.

type Type

type Type byte

Type defines the message payload type.

const (
	// TypeControl represents a control message.
	TypeControl Type = iota
	// TypeText represents a text message.
	TypeText
	// TypeBinary represents a binary message.
	TypeBinary
)

Jump to

Keyboard shortcuts

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