🎄 Happy Holidays! 🥳

Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.

Happy Holidays!

Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.

Messaging in the C API

Hello,
I am using the Solace C API for my project. The data that we want to pass between the applications is an array of a structure. The structure has around 150-200 fields of int/long/short/char. The array size will be around 1,000 - 50,000.
Currently I am using a stream to pass the fields. I start a loop of array size and individually add the structure fields to my stream container.
Is there any other easier way to pass a structure as a message and extract it back to a structure at the receiver?

Best Answer

  • TomF
    TomF Member, Employee Posts: 412 Solace Employee
    #2 Answer ✓

    Hello @chaudharys, what you're describing here is the classic message serialisation challenge.

    If your system is homogenous (i.e. same processor macro architecture, same size, so say all x86_64) you could get away with simply sending as a binary blob.

    This is dangerous, though. If your system is heterogenous (a mixture of x86 and, say ARM based mobile devices or embedded devices) then you need to abstract the byte- and endian-ness. CCSMPs SDTs do this for you, but as you've experienced they aren't intended as a general solution to the serialisation problem: a frequent use case for them is to create a kind of header or meta-data that describes, say, a machine dependent binary blob in a machine independent way.

    Have you considered using a serialisation package such as Google Protocol Buffers? These packages do almost all of this work for you.

Answers

  • TomF
    TomF Member, Employee Posts: 412 Solace Employee
    #3 Answer ✓

    Hello @chaudharys, what you're describing here is the classic message serialisation challenge.

    If your system is homogenous (i.e. same processor macro architecture, same size, so say all x86_64) you could get away with simply sending as a binary blob.

    This is dangerous, though. If your system is heterogenous (a mixture of x86 and, say ARM based mobile devices or embedded devices) then you need to abstract the byte- and endian-ness. CCSMPs SDTs do this for you, but as you've experienced they aren't intended as a general solution to the serialisation problem: a frequent use case for them is to create a kind of header or meta-data that describes, say, a machine dependent binary blob in a machine independent way.

    Have you considered using a serialisation package such as Google Protocol Buffers? These packages do almost all of this work for you.