Archived

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

a small question

Given such a slice:
module test
{
sequence<byte> Image;
interface Process
{
Image getImage();
};
};

It is OK but the generated c# and java(except C++) codes convert the Image type directly to byte<>. This is of course right but in some cases a human readable word such Image is more preferable just as done in slice2cpp.
The reason may exist in the lack of typedef in java and c#. I have gooled Inet and gotten some workgrounds recommended by some articles. I want to know what your opinions are about it.

Thanks

OrNot

Comments

  • Slice deliberately does not offer typedef. The reason is that typedefs tend to do more harm than good: they create aliases for types and, if typedefs are used, they can be difficult to map to other langues. As you say, Java and C# do not offer typedef so, at the language level, any Slice typedefs would have to be thrown away anyway.

    Have a look at CORBA to see the mess that is created by typedefs. In particular, the IFR, type any, and TypeCodes suffer from a lot of needless complexity in order to provide a feature whose value is questionable, at best.

    Cheers,

    Michi.
  • hi, Michi,
    The reason why I ask this quesiton is that when I define the above slice, I feel a bit suprise that I can not find the Image type in the generated codes in C# and Java any more. So I just want to know if it is feasible to offer some workground in slice2cs and slice2java to simulate the C++ typedef. So far as not offer the typedef at slice level, I can not agree with you any more. :)
  • What about creating a sort of Holder such as:
    public class Image {
    protected byte []data;

    public byte[] getData() {
    return data;
    }
    public void setData(byte[] d) {
    data = d;
    }

    Maybe with a slice directive...

    Guido.
  • bernard
    bernard Jupiter, FL
    In Slice, you can always create a struct around your data, e.g.

    struct Image
    {
    Ice::ByteSeq bytes;
    };

    On-the-wire, it's like sending just the bytes.

    Cheers,
    Bernard