Archived
This forum has been archived. Please start a new discussion on GitHub.
Slice and array???
Hello,
I've a question about Slice:
How is it possible to define a transmit or return value of an array?
In the documentation I didn't found some examples by using an array.
example how I would like to use it at XXX.java:
but how is the definition in Slice XXX.ice:
Has somebody an solution or example ?
Thanks a lot greetings surfer
I've a question about Slice:
How is it possible to define a transmit or return value of an array?
In the documentation I didn't found some examples by using an array.
example how I would like to use it at XXX.java:
public String[] getArray(Ice.Current current){ String [] array = new String[100]; array[0] = "test1"; array[1] = "test2"; array[2] = "test3"; ................ return array } public int getArraySize(String[] array, Ice.Current current){ int iSize = array.length; return iSize }
but how is the definition in Slice XXX.ice:
#ifndef XXX_ICE #define XXX_ICE // here the array definitions ????????????????? module YYY { interface xxx { nonmutating string String[] getArray(); nonmutating int getArraySize(String[] array); }; }; #endif
Has somebody an solution or example ?
Thanks a lot greetings surfer
0
Comments
-
You must use sequences. Please see the Ice manual for details.0
-
My solution ??
Hallo Marc,
thanks a lot for your tip !!!
Here the code which works for me. Please correct me if something is wrong.
Hello.ice:#ifndef HELLO_ICE #define HELLO_ICE module Demo { exception GenericError { string reason; }; sequence<string> sa; interface Hello { nonmutating void sayHello(); idempotent void shutdown(); nonmutating sa getArray(); nonmutating void sendArray(sa text); }; }; #endif
HelloI.java:public String[] getArray(Ice.Current current) { array = new String[100]; array[0] = "Test0"; array[1] = "Test1"; array[2] = "Test2"; array[3] = "Test3"; return array; } public void sendArray(String[] arrayGet, Ice.Current current) { array = arrayGet; int iCounter = 0; while(iCounter<4){ String s = array[iCounter]; System.out.println("Array content "+iCounter+":>"+s); iCounter++; } }
Client.java:if(line.equals("t")) { twoway.sayHello(); String[] sa = twoway.getArray(); int iCounter = 0; while(iCounter<4){ String s = sa[iCounter]; System.out.println("Client content "+iCounter+":>"+s); iCounter++; } } else if(line.equals("o")) { oneway.sayHello(); String[] array = new String[100]; array[0] = "C_Test0"; array[1] = "C_Test1"; array[2] = "C_Test2"; array[3] = "C_Test3"; twoway.sendArray(array); }
Thanks a lot
greetings surfer0 -
surfer wrote:
public String[] getArray(Ice.Current current) { array = new String[100]; array[0] = "Test0"; array[1] = "Test1"; array[2] = "Test2"; array[3] = "Test3"; return array; } public void sendArray(String[] arrayGet, Ice.Current current) { array = arrayGet; int iCounter = 0; while(iCounter<4){ String s = array[iCounter]; System.out.println("Array content "+iCounter+":>"+s); iCounter++; } }
Why allocate an array of 100 elements when you are sending only four elements? When you return this array, the Ice run time will marshal 4 non-empty strings, followed by 96 empty strings.Client.java:twoway.sayHello(); String[] sa = twoway.getArray(); int iCounter = 0; while(iCounter<4){ String s = sa[iCounter]; System.out.println("Client content "+iCounter+":>"+s); iCounter++; }
String[] sa = twoway.getArray(); int iCounter = 0; while(iCounter < sa.length) System.out.println(sa[iCounter]);
Cheers,
Michi.0 -
Hello michi,
thanks for your answer,
I've just set the array size to 100 for testing not for special use.
But I will attend that in my application.
Thanks a lot
greetings surfer0