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: 406 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: 406 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.