Class DefaultKafkaMessageSerializer
The default implementation of a IKafkaMessageSerializer simply uses the provided IMessageSerializer for the value and treats the key as a UTF-8 encoded string.
Inherited Members
Namespace: Silverback.Messaging.Serialization
Assembly: Silverback.Integration.Kafka.dll
Syntax
public class DefaultKafkaMessageSerializer : IKafkaMessageSerializer, IMessageSerializer
Constructors
| Improve this doc View sourceDefaultKafkaMessageSerializer(IMessageSerializer)
Initializes a new instance of the DefaultKafkaMessageSerializer class.
Declaration
public DefaultKafkaMessageSerializer(IMessageSerializer serializer)
Parameters
Type | Name | Description |
---|---|---|
IMessageSerializer | serializer | The IMessageSerializer to be used. |
Properties
| Improve this doc View sourceRequireHeaders
Gets a value indicating whether headers are mandatory for this serializer implementation or configuration to work properly.
Declaration
public bool RequireHeaders { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
| Improve this doc View sourceDeserializeAsync(Stream?, MessageHeaderCollection, MessageSerializationContext)
Deserializes the byte array back into a message object.
Declaration
public ValueTask<(object? Message, Type MessageType)> DeserializeAsync(Stream? messageStream, MessageHeaderCollection messageHeaders, MessageSerializationContext context)
Parameters
Type | Name | Description |
---|---|---|
Stream | messageStream | The Stream containing the message to be deserialized. |
MessageHeaderCollection | messageHeaders | The message headers collection. |
MessageSerializationContext | context | The context information. |
Returns
Type | Description |
---|---|
ValueTask<(object Message, Type MessageType)> | A Task<TResult> representing the asynchronous operation. The task result contains the
deserialized message (or |
DeserializeKey(byte[], IReadOnlyCollection<MessageHeader>, MessageSerializationContext)
Deserializes the byte array back into a key string.
Declaration
public string DeserializeKey(byte[] key, IReadOnlyCollection<MessageHeader> messageHeaders, MessageSerializationContext context)
Parameters
Type | Name | Description |
---|---|---|
byte[] | key | The byte array to be deserialized. |
IReadOnlyCollection<MessageHeader> | messageHeaders | The message headers collection. |
MessageSerializationContext | context | The context information. |
Returns
Type | Description |
---|---|
string | The deserialized key. |
SerializeAsync(object?, MessageHeaderCollection, MessageSerializationContext)
Serializes the specified message object into a byte array.
Declaration
public ValueTask<Stream?> SerializeAsync(object? message, MessageHeaderCollection messageHeaders, MessageSerializationContext context)
Parameters
Type | Name | Description |
---|---|---|
object | message | The message object to be serialized. |
MessageHeaderCollection | messageHeaders | The message headers collection. |
MessageSerializationContext | context | The context information. |
Returns
Type | Description |
---|---|
ValueTask<Stream> | A Task<TResult> representing the asynchronous operation. The task result contains the Stream with the serialized message. |
SerializeKey(string, IReadOnlyCollection<MessageHeader>, MessageSerializationContext)
Serializes the specified key string into a byte array.
Declaration
public byte[] SerializeKey(string key, IReadOnlyCollection<MessageHeader> messageHeaders, MessageSerializationContext context)
Parameters
Type | Name | Description |
---|---|---|
string | key | The message key to be serialized. |
IReadOnlyCollection<MessageHeader> | messageHeaders | The message headers collection. |
MessageSerializationContext | context | The context information. |
Returns
Type | Description |
---|---|
byte[] | The serialization result. |