Table of Contents

Class MemoryMessageOfT<T>

Namespace
Excalibur.Dispatch.Messaging
Assembly
Excalibur.Dispatch.dll

A typed message implementation that provides both Memory<byte> and typed access to content.

public sealed class MemoryMessageOfT<T> : IMemoryMessage<T>, IMemoryMessage, IDispatchMessage, IDisposable where T : class

Type Parameters

T

The type of the message content.

Inheritance
MemoryMessageOfT<T>
Implements
Inherited Members
Extension Methods

Constructors

MemoryMessageOfT(IMemoryOwner<byte>, DispatchJsonSerializer, int, string)

Initializes a new instance of the MemoryMessageOfT<T> class with owned memory and explicit payload length.

public MemoryMessageOfT(IMemoryOwner<byte> memoryOwner, DispatchJsonSerializer serializer, int payloadLength, string contentType = "application/json")

Parameters

memoryOwner IMemoryOwner<byte>

The memory owner that manages the message body.

serializer DispatchJsonSerializer

The serializer for deserializing content.

payloadLength int

The valid payload length within memoryOwner memory.

contentType string

The content type of the message body.

MemoryMessageOfT(IMemoryOwner<byte>, DispatchJsonSerializer, string)

Initializes a new instance of the MemoryMessageOfT<T> class with owned memory.

public MemoryMessageOfT(IMemoryOwner<byte> memoryOwner, DispatchJsonSerializer serializer, string contentType = "application/json")

Parameters

memoryOwner IMemoryOwner<byte>

The memory owner that manages the message body.

serializer DispatchJsonSerializer

The serializer for deserializing content.

contentType string

The content type of the message body.

MemoryMessageOfT(Memory<byte>, DispatchJsonSerializer, string)

Initializes a new instance of the MemoryMessageOfT<T> class with borrowed memory.

public MemoryMessageOfT(Memory<byte> body, DispatchJsonSerializer serializer, string contentType)

Parameters

body Memory<byte>

The message body as borrowed memory.

serializer DispatchJsonSerializer

The serializer for deserializing content.

contentType string

The content type of the message body.

MemoryMessageOfT(T, IMemoryOwner<byte>, int, string)

Initializes a new instance of the MemoryMessageOfT<T> class with pre-deserialized content and owned memory.

public MemoryMessageOfT(T content, IMemoryOwner<byte> memoryOwner, int payloadLength, string contentType = "application/json")

Parameters

content T

The pre-deserialized content.

memoryOwner IMemoryOwner<byte>

The memory owner that manages the message body.

payloadLength int

The valid payload length within memoryOwner memory.

contentType string

The content type of the message body.

MemoryMessageOfT(T, Memory<byte>, string)

Initializes a new instance of the MemoryMessageOfT<T> class with pre-deserialized content.

public MemoryMessageOfT(T content, Memory<byte> body, string contentType)

Parameters

content T

The pre-deserialized content.

body Memory<byte>

The message body as memory.

contentType string

The content type of the message body.

Properties

Body

Gets the message body as a Memory<byte>.

public Memory<byte> Body { get; }

Property Value

Memory<byte>

The memory-backed payload for the message.

Remarks

This property enables zero-copy message processing by allowing messages to reference memory directly without copying data. The memory should remain valid for the lifetime of the message processing.

Content

Gets the deserialized message content.

public T Content { get; }

Property Value

T

The deserialized representation of the payload.

Remarks

This property may lazily deserialize the content from the Body on first access.

ContentType

Gets the content type of the message body.

public string ContentType { get; }

Property Value

string

The MIME content type of the payload.

Remarks

Common values include "application/json", "application/octet-stream", "text/plain", etc. This helps consumers understand how to interpret the Body data.

Features

public IMessageFeatures Features { get; }

Property Value

IMessageFeatures

Headers

public IReadOnlyDictionary<string, object> Headers { get; }

Property Value

IReadOnlyDictionary<string, object>

Id

public Guid Id { get; }

Property Value

Guid

IsDeserialized

Gets a value indicating whether the content has been deserialized.

public bool IsDeserialized { get; }

Property Value

bool

true when the payload has been materialized; otherwise, false.

MessageId

public string MessageId { get; }

Property Value

string

MessageType

public string MessageType { get; }

Property Value

string

OwnsMemory

Gets a value indicating whether the body memory is owned by this message.

public bool OwnsMemory { get; }

Property Value

bool

true if the message owns the underlying memory; otherwise, false.

Remarks

When true, the message is responsible for managing the lifetime of the memory. When false, the memory is borrowed and should not be disposed by the message.

Timestamp

public DateTimeOffset Timestamp { get; }

Property Value

DateTimeOffset

Methods

Dispose()

Disposes the message and returns any owned memory to the pool.

public void Dispose()