msg

package
v4.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 3 Imported by: 2

Documentation

Overview

Package msg provides message types and codecs for event-based communication.

Index

Constants

View Source
const (
	// Delimiter is the separator used between event name, ack ID, and data.
	Delimiter = "||"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec added in v4.1.0

type Codec interface {
	// UnmarshalEvent decodes event data from bytes.
	UnmarshalEvent(data []byte) (Event, error)
	// EncodeEvent encodes an event to bytes.
	EncodeEvent(w *bytes.Buffer, event Event) error
}

Codec defines an interface for encoding and decoding events.

type Event

type Event struct {
	Name  string
	AckId uint64
	Data  []byte
}

Event represents a communication event with a name, optional acknowledgment ID, and data payload.

func (Event) IsAckRequired

func (e Event) IsAckRequired() bool

IsAckRequired returns true if the event requires an acknowledgment.

type LineCodec added in v4.1.0

type LineCodec struct{}

LineCodec is a simple text-based codec that uses "||" as a delimiter. The format is: <eventName>||<ackId>||<eventData>

func NewLineCodec added in v4.1.0

func NewLineCodec() LineCodec

NewLineCodec creates a new LineCodec instance.

func (LineCodec) EncodeEvent added in v4.1.0

func (LineCodec) EncodeEvent(buff *bytes.Buffer, event Event) error

EncodeEvent encodes an event to the line-based format.

func (LineCodec) UnmarshalEvent added in v4.1.0

func (LineCodec) UnmarshalEvent(data []byte) (Event, error)

UnmarshalEvent decodes an event from the line-based format. It returns an error if the format is invalid or if the ackId cannot be parsed.

Jump to

Keyboard shortcuts

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