Archived

This forum has been archived. Please start a new discussion on GitHub.

Dispatching legacy C++ messages via Ice

I have a legacy C++ single threaded application that receives messages over sockets and deserialises each message payload into its corresponding C++ class object. The class objects are then dispatched to various modules within the program.

I now want to modify the program to be either multithreaded or multi-process. If I go multi-process I need a mechanism to dispatch messages to each process. If I use Ice I could replicate all the message definitions as Ice (there are quite a lot of messages), or can I simply send the existing message object as a blob of bytes and let the receiving end typecast the blob back to the message? What Ice mechanism could I use to exchange message blobs? Are there issues with sending classes over the wire as blobs?

Regards John

Comments

  • benoit
    benoit Rennes, France
    Hi John,

    You can just use a sequence of bytes "in" param to transmit your serialized data:
    // Slice
    
    sequence<byte> ByteSeq;
    
    interface MyIntf
    {
        void op1(ByteSeq param);
    };
    

    Your application will be responsible for serializing/de-serializing the data. The drawback with using such blobs in the Slice is the loss of type-safety at the Slice level and the fact that it's not easily portable to another language (if you used Slice types to encode your classes, portability to other language mappings would come at no cost). This is probably fine for your application however.

    Note that Ice for Java and C# provide a Slice serialize metadata which allows to pass Java/C# native types directly to the Slice generated code (proxies/servants). The generated code, under the hood, takes care of the serialization to or from the byte sequence. This is possible because Java and C# both provide standard APIs for serialization. In C++, this is currently not possible, mostly because there are no standard serialization APIs (but this is something which could be added).

    So if you have a large number of classes and want to reduce the boiler plate code to serialize/de-serialize your classes to/from the byte sequence, an option would be to implement something similar to Java/C#. You could directly pass your native classes to the Slice generated code and have the generated code take care of the serialization/de-serialization. For an example on how this metadata could work, see the Java and C# demo/Ice/serialize in your Ice 3.4b distribution. If you are interested in sponsoring such a feature, please contact us at info@zeroc.com

    Cheers,
    Benoit.
  • Is the serialization metadata for Java new in 3.4b? I've never noticed it before ... very cool. :)

    MEF
  • benoit
    benoit Rennes, France
    It's not new, it was added with Ice 3.3.1, see Ice 3.3.1 RELEASE_NOTES.

    Cheers,
    Benoit.