Class MemoryMessageOfT<T>
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
TThe 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
memoryOwnerIMemoryOwner<byte>The memory owner that manages the message body.
serializerDispatchJsonSerializerThe serializer for deserializing content.
payloadLengthintThe valid payload length within
memoryOwnermemory.contentTypestringThe 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
memoryOwnerIMemoryOwner<byte>The memory owner that manages the message body.
serializerDispatchJsonSerializerThe serializer for deserializing content.
contentTypestringThe 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
bodyMemory<byte>The message body as borrowed memory.
serializerDispatchJsonSerializerThe serializer for deserializing content.
contentTypestringThe 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
contentTThe pre-deserialized content.
memoryOwnerIMemoryOwner<byte>The memory owner that manages the message body.
payloadLengthintThe valid payload length within
memoryOwnermemory.contentTypestringThe 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
contentTThe pre-deserialized content.
bodyMemory<byte>The message body as memory.
contentTypestringThe content type of the message body.
Properties
Body
Gets the message body as a Memory<byte>.
public Memory<byte> Body { get; }
Property Value
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
Headers
public IReadOnlyDictionary<string, object> Headers { get; }
Property Value
Id
public Guid Id { get; }
Property Value
IsDeserialized
Gets a value indicating whether the content has been deserialized.
public bool IsDeserialized { get; }
Property Value
MessageId
public string MessageId { get; }
Property Value
MessageType
public string MessageType { get; }
Property Value
OwnsMemory
Gets a value indicating whether the body memory is owned by this message.
public bool OwnsMemory { get; }
Property Value
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
Methods
Dispose()
Disposes the message and returns any owned memory to the pool.
public void Dispose()