Interface IRingKernelMessage
- Namespace
- DotCompute.Abstractions.Messaging
- Assembly
- DotCompute.Abstractions.dll
Base interface for type-safe messages exchanged between Ring Kernels.
public interface IRingKernelMessage
Remarks
Ring Kernel messages provide type-safe communication between GPU-resident actors in the Orleans.GpuBridge.Core integration. Messages support:
- Unique identification for tracking and deduplication
- Priority-based processing
- Correlation for request/response patterns
- Zero-copy serialization using spans
Implementations should be generated using the [GenerateMessageSerializer] attribute to ensure optimal serialization performance.
Example:
[GenerateMessageSerializer]
public partial class ComputeRequest : IRingKernelMessage
{
public Guid MessageId { get; set; } = Guid.NewGuid();
public string MessageType => "ComputeRequest";
public byte Priority { get; set; } = 128;
public Guid? CorrelationId { get; set; }
// Application data
public int InputValue { get; set; }
public float[] Data { get; set; } = Array.Empty<float>();
// Serialization auto-generated by source generator
}
Properties
CorrelationId
Gets or sets the optional correlation identifier for request/response patterns.
Guid? CorrelationId { get; set; }
Property Value
- Guid?
Remarks
Used to correlate responses with their originating requests. Set to the MessageId of the request message when sending a response.
Null for standalone messages that don't require correlation.
MessageId
Gets or sets the unique message identifier.
Guid MessageId { get; set; }
Property Value
Remarks
Used for message tracking, logging, and deduplication. Should be unique across all messages in the system. Default: NewGuid()
MessageType
Gets the message type identifier for deserialization.
string MessageType { get; }
Property Value
Remarks
Used by the runtime to determine which concrete type to instantiate during deserialization. Must be consistent across all instances of the same message type.
Typically returns the type name (e.g., "ComputeRequest").
PayloadSize
Gets the message payload size in bytes.
int PayloadSize { get; }
Property Value
Remarks
Returns the total size of the serialized message including:
- MessageId (16 bytes)
- Priority (1 byte)
- CorrelationId (16 bytes if present, 1 byte null marker otherwise)
- Application data (variable)
Used for memory allocation and capacity planning. Source generator calculates this automatically.
Priority
Gets or sets the message priority (0-255).
byte Priority { get; set; }
Property Value
Remarks
Higher values indicate higher priority. Used by priority queues to determine processing order.
- 0-63: Low priority (batch processing)
- 64-127: Normal priority (default)
- 128-191: High priority (interactive)
- 192-255: Critical priority (system messages)
Default: 128 (normal priority)
Methods
Deserialize(ReadOnlySpan<byte>)
Deserializes the message from a byte span.
void Deserialize(ReadOnlySpan<byte> data)
Parameters
dataReadOnlySpan<byte>The serialized message bytes.
Remarks
Reads data using BinaryPrimitives with explicit endianness (little-endian).
The data span must be at least PayloadSize bytes.
Auto-generated by source generator for optimal performance.
Serialize()
Serializes the message to a byte span.
ReadOnlySpan<byte> Serialize()
Returns
- ReadOnlySpan<byte>
A read-only span containing the serialized message bytes.
Remarks
Uses BinaryPrimitives for efficient serialization with explicit endianness (little-endian).
The returned span is valid only until the next call to Serialize(). Callers should copy the data if longer retention is needed.
Auto-generated by source generator for optimal performance.