Jump to content
OpenSplice DDS Forum
mdbk

C# no content is passed with sequence<char>?

Recommended Posts

Using: VortexOpenSplice-6.7.170912OSS-HDE-x86_64.win-vs2015

I've received some IDL that utilizes sequence<char> for passing strings (rather than char[] or string); it appears that in C# this doesn't actually pass the value through.  (Note that this works fine in C++)

This can be easily reproduced in the HelloWorld sample as follows:

  1. Change the HelloWorldData.idl:
    • Replace:
    • string message;

      With:

      sequence<char,16> message;

       

  2. Change the HellowWorldDataPublisher.cs:
    • Replace:
    • msgInstance.message = "Hello World";

      With:

      string str = "Hello World";
      char[] array = new char[16];
      Array.Copy(str.ToCharArray(), array, str.Length);
      msgInstance.message = array;

       

  3. Run the HelloWorld sample app and you'll see that the received message in the HelloWorldDataSubscriber has no content (is of length 0)
  4. Note that in the IDL if you use a char<16> rather than a sequence<char,16> it works as expected and you get the "Hello World" in the subscriber.

 

Can you please advise on whether this is a usage problem, code generation problem or something else?  (and if there's a workaround short of changing the IDL)

Thank you very much.

 

 

 

 

Share this post


Link to post
Share on other sites

Hi ,

Please check your HelloWorldSplDcps.cs .

In CopyIn method , code like below

public V_COPYIN_RESULT CopyIn(System.IntPtr typePtr, DataType from, ref __DataType to)
        {
            if (from == null) return V_COPYIN_RESULT.INVALID;
            to.id = from.id;
            if (from.msg == null) return V_COPYIN_RESULT.INVALID;
            // Unbounded string: bounds check not required...
            if (!Write(c.getBase(typePtr), ref to.msg, from.msg)) return V_COPYIN_RESULT.OUT_OF_MEMORY;
            if (from.payload == null) return V_COPYIN_RESULT.INVALID;
            int attr2Seq0Length = from.payload.Length;
            // Unbounded sequence: bounds check not required...
            if (attr2Seq0Type == IntPtr.Zero) {
                IntPtr memberOwnerType = DDS.OpenSplice.Database.c.resolve(c.getBase(typePtr), fullyScopedName);
                IntPtr specifier = DDS.OpenSplice.Database.c.metaResolveSpecifier(memberOwnerType, "payload");
                IntPtr specifierType = DDS.OpenSplice.Database.c.specifierType(specifier);
                attr2Seq0Type = DDS.OpenSplice.Database.c.typeActualType(specifierType);
            }
            IntPtr attr2Seq0Buf = DDS.OpenSplice.Database.c.newSequence(attr2Seq0Type, attr2Seq0Length);
            if (attr2Seq0Buf == IntPtr.Zero) return V_COPYIN_RESULT.OUT_OF_MEMORY;
            Marshal.Copy(from.payload, 0, attr2Seq0Buf, attr2Seq0Length);
            return V_COPYIN_RESULT.OK;
        }

You have to modify code yourself to replace " attr2Seq0Buf " to " to.something " , which is according to your sequence structure .

This was a idlpp bug which I have reported and fixed in OpenSplice 6.8.2 version .

If this help you , you need this workaround or update to new version .

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×