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

int org::rosuda::JRclient::REXP::getBinaryRepresentation ( byte[]  buf,
int  off 
) [inline]

Stores the REXP in its binary (ready-to-send) representation including header into a buffer and returns the index of the byte behind the REXP.

Please note that currently only XT_[ARRAY_]INT, XT_[ARRAY_]DOUBLE and XT_[ARRAY_]STR are supported! All other types will be stored as SEXP of the length 0 without any contents.

Parameters:
buf buffer to store the REXP binary into
off offset of the first byte where to store the REXP
Returns:
the offset of the first byte behind the stored REXP

Definition at line 377 of file REXP.java.

References asDouble(), asInt(), cont, getBinaryLength(), Xt, XT_ARRAY_DOUBLE, XT_ARRAY_INT, XT_ARRAY_STR, XT_DOUBLE, and XT_INT.

                                                            {
      int myl=getBinaryLength();
        boolean isLarge=(myl>0xfffff0);
        Rtalk.setHdr(Xt,myl-(isLarge?8:4),buf,off);
        off+=(isLarge?8:4);
      switch (Xt) {
      case XT_INT: Rtalk.setInt(asInt(),buf,off); break;
      case XT_DOUBLE: Rtalk.setLong(Double.doubleToLongBits(asDouble()),buf,off); break;
      case XT_ARRAY_INT:
          if (cont!=null) {
            int ia[]=(int[])cont;
            int i=0, io=off;
            while(i<ia.length) {
                Rtalk.setInt(ia[i++],buf,io); io+=4;
            }
          }
          break;
      case XT_ARRAY_DOUBLE:
          if (cont!=null) {
            double da[]=(double[])cont;
            int i=0, io=off;
            while(i<da.length) {
                Rtalk.setLong(Double.doubleToLongBits(da[i++]),buf,io); io+=8;
            }
          }
          break;
      case XT_ARRAY_STR:
        if (cont!=null) {
          String sa[]=(String[])cont;
          int i=0, io=off;
          while (i<sa.length) {
            if (sa[i]!=null) {
            try {
              byte b[]=sa[i].getBytes(Rconnection.transferCharset);
              System.arraycopy(b,0,buf,io,b.length);
              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
            }
            }
            buf[io++]=0;
            i++;
          }
          i=io-off;
          while ((i&3)!=0) { buf[io++]=1; i++; } // padding if necessary..
        }
      }
      return off+myl;
    }


Generated by  Doxygen 1.6.0   Back to index