Getting Started

This guide will help you start using Solace Generic SERDES for .NET in your applications.

Installation

Install the NuGet package:

dotnet add package Solace.Serdes

Basic Usage

Using StringSerializer and StringDeserializer

The library includes built-in StringSerializer and StringDeserializer implementations that handle string-to-bytes conversion using UTF-8 encoding.

Creating a Serializer

using Solace.Serdes;

// Create a string serializer (uses UTF-8 by default)
var serializer = new StringSerializer();

// Serialize a string to bytes
string message = "Hello World";
byte[] data = serializer.Serialize("topic", message);

Creating a Deserializer

using Solace.Serdes;

// Create a string deserializer (uses UTF-8 by default)
var deserializer = new StringDeserializer();

// Deserialize bytes to a string
byte[] data = /* received message bytes */;
string message = deserializer.Deserialize("topic", data);

Integration with Solace CSCSMP API

When using with the Solace CSCSMP .NET API, you can use extension methods for seamless integration:

using Solace.Serdes;
using SolaceSystems.Solclient.Messaging;

var serializer = new StringSerializer();
var deserializer = new StringDeserializer();

// Publishing a message
using (IMessage message = ContextFactory.Instance.CreateMessage())
{
    message.Destination = topic;

    // Serialize and set message payload
    message.Serialize(serializer, "Hello World");

    session.Send(message);
}

// Receiving a message
void HandleMessage(object source, MessageEventArgs args)
{
    // Deserialize the message payload
    string receivedText = args.Message.Deserialize(deserializer);

    Console.WriteLine("Received: " + receivedText);
}

Implementing Custom Serializers

You can implement custom serializers for any data format by implementing the core interfaces:

using Solace.Serdes;
using System.Collections.Generic;
using System.Text.Json;

public class JsonSerializer<T> : ISerializer<T>
{
    public void Configure(IDictionary<string, object> properties)
    {
        // Configure serializer if needed
    }

    public byte[] Serialize(string destinationName, T data,
        IDictionary<string, object> headers = null)
    {
        if (data == null)
            return null;

        return JsonSerializer.SerializeToUtf8Bytes(data);
    }
}

Additional Examples

For complete working examples, including integration with Solace messaging, visit the Solace Samples for .NET repository.