Class MemoryMessage
A message implementation that holds its content as Memory<byte> for zero-copy operations.
public sealed class MemoryMessage : IMemoryMessage, IDispatchMessage, IDisposable
- Inheritance
-
MemoryMessage
- Implements
- Inherited Members
- Extension Methods
Constructors
MemoryMessage(IMemoryOwner<byte>, int, string)
Initializes a new instance of the MemoryMessage class with owned memory and explicit payload length.
public MemoryMessage(IMemoryOwner<byte> memoryOwner, int payloadLength, string contentType = "application/octet-stream")
Parameters
memoryOwnerIMemoryOwner<byte>The memory owner that manages the message body.
payloadLengthintThe valid payload length within
memoryOwnermemory.contentTypestringThe content type of the message body.
MemoryMessage(IMemoryOwner<byte>, string)
Initializes a new instance of the MemoryMessage class with owned memory.
public MemoryMessage(IMemoryOwner<byte> memoryOwner, string contentType = "application/octet-stream")
Parameters
memoryOwnerIMemoryOwner<byte>The memory owner that manages the message body.
contentTypestringThe content type of the message body.
MemoryMessage(Memory<byte>, string)
Initializes a new instance of the MemoryMessage class with borrowed memory.
public MemoryMessage(Memory<byte> body, string contentType)
Parameters
bodyMemory<byte>The message body as borrowed 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.
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
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()