Logo Search packages:      
Sourcecode: rserve version File versions  Download package

int org::rosuda::JRclient::REXP::getBinaryLength (  )  [inline]

Calculates the length of the binary representation of the REXP including all headers. This is the amount of memory necessary to store the REXP via getBinaryRepresentation.

Please note that currently only XT_[ARRAY_]INT, XT_[ARRAY_]DOUBLE and XT_[ARRAY_]STR are supported! All other types will return 4 which is the size of the header.

Returns:
length of the REXP including headers (4 or 8 bytes)

Definition at line 334 of file REXP.java.

References cachedBinaryLength, cont, Xt, XT_ARRAY_DOUBLE, XT_ARRAY_INT, XT_ARRAY_STR, XT_DOUBLE, XT_INT, and XT_STR.

Referenced by getBinaryRepresentation().

                                 {
      int l=0;
      switch (Xt) {
      case XT_INT: l=4; break;
      case XT_DOUBLE: l=8; break;
      case XT_STR: l=(cont==null)?1:((String)cont).length()+1; break;
      case XT_ARRAY_INT: l=(cont==null)?0:((int[])cont).length*4; break;
      case XT_ARRAY_DOUBLE: l=(cont==null)?0:((double[])cont).length*8; break;
      case XT_ARRAY_STR:
        if (cachedBinaryLength<0) { // if there's no cache, we have to count..
          if (cont==null) cachedBinaryLength=4; else {
            String sa[]=(String[])cont;
            int i=0, io=0;
            while (i<sa.length) {
            if (sa[i]!=null) {
              try {
                byte b[]=sa[i].getBytes(Rconnection.transferCharset);
                io+=b.length;
                b=null;
              } catch (java.io.UnsupportedEncodingException uex) {
                // FIXME: we should so something ... so far we hope noone's gonna mess with the encoding
              }
            }
            io++;
            i++;
            }
            while ((io&3)!=0) io++;
            cachedBinaryLength=io+4;
            if (cachedBinaryLength>0xfffff0)
            cachedBinaryLength+=4;
          }
        }
        return (int)cachedBinaryLength;
      } // switch
        if (l>0xfffff0) l+=4; // large data need 4 more bytes
      return l+4;
    }


Generated by  Doxygen 1.6.0   Back to index