Search code examples
data-distribution-service

Publish files in open splice DDS


I have successfully created a publisher and subscriber with primitive types. Now I have a problem when trying to publish a file (like xml, txt, video, audio etc) to DDS. I don't know how to specify the types in IDL file and how to publish the whole file to DDS (also how to receive the file on the subscriber side).

And one more question: "Are there any memory limitations to publishing in DDS?"


Solution

  • There are several routes you can go for distributing a file using DDS. The most straightforward (but not necessarily the best) is using a sequence of octets (bytes) to capture the contents of the file. This can be achieved by an IDL definition like this:

    const long MAX_NAME_LEN = 128;
    const long MAX_FILE_SIZE = 100000;
    
    typedef string<MAX_NAME_LEN> NameType;
    typedef sequence<octet,MAX_FILE_SIZE> BinaryContentsType;
    
    struct BinaryFile {
        NameType name; //@key
        BinaryContentsType contents;
    };
    #pragma keylist BinaryFile name
    

    Since your question is not specific for OpenSplice DDS, but could be applied to any DDS implementation, I have included syntax for defining the key attribute such that it works with several implementations.

    In your application, you will have to instantiate the type and fill the values of the members. This will look something like

    BinaryFile instance = new BinaryFile();
    instance.name = "SomeFileName";
    // fill instance.contents by reading file into array of bytes.
    

    The contents attribute will be an array of bytes. After the contents have been filled, just invoke the write method on a BinaryFileDataWriter, similar to what other examples do.

    There is no real limit to the size of the file distributed this way other than the limits of the shared memory as configured. However, it is good practice to impose a limit on the size, which is why the sequence in the BinaryContentsType type is bounded.

    You have not mentioned what programming language you are using, so it is hard to give any coding details. But since you mentioned that you did get started with basic types, it should be easy to figure out how to publish the BinaryFileType type, especially if you take a look at the provided documentation and examples and apply that to your own type.

    As a note on the side, are you sure that you want to distribute complete files? Depending on the situation, a better approach might be to analyse the structure of the contents of the file and create a data-model that matches that. You would be reading the file on the publisher side and translate it into meaningful data-items as opposed to a blob. That way, subscribers can take advantage of more advanced data management features, like subscribing to a subset of the contents by subscribing to a subset of the available Topics only, or by using a filter based on content. Whether this makes sense all depends on your use case though.