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

determine messagesize during runtime


is there any way to calculate the message size of a method invokation?

i have a sequence or dictionary which shall be transmitted to the server.
in case the sequence is too long - i need to splitt the sequence and
perform multiple invokations.

but: what is the max length/count of the sequence/dictionary?

i can do it with an try and error approach to find out, but calculating it
during runtime would really be nice.

thx & cu tom


  • benoit
    benoit Rennes, France
    Hi Tom,

    You could use the streaming API: you create an output stream, write the data to the output stream and get the size of the resulting byte sequence. Note that this is a bit expensive however because you'll need to marshall twice the data (unless you send the byte sequence directly and use the streaming API on the receiving side to umarshall the data). And to be exact, you'll also need to take into account the size of the Ice message and request header (see Chapter 33.3 in the Ice Manual).

    The Chapter 35 in the Ice manual documents how to use the streaming API and you'll also find a demo in demo/Ice/invoke.

  • Hi Benoit,

    thanks for the hint!
    Marshall twice doesn't sound very good to tell the truth.

    What about making the compiler to add message size calculation routines
    to the generated types?
    This way we atleast know the sizes of method parameters.

    Getting the size of message and request headers shouldn't be so
    complicated - the proxy/connection could give us this info.

    Well - just an idea!

    CU Tom
  • benoit
    benoit Rennes, France
    Hi Tom,

    It would work for sequences or dictionaries with fixed size types but for variable size types, you would still need to go through the whole sequence or dictionnary to figure out its size.

    Also, if you're using only fixed size types, you only need to marshall once a sequence/dictionary element with the streaming API to figure out its size.