]> gerrit.simantics Code Review - simantics/r.git/blob - bundles/org.simantics.r.scl/src/org/rosuda/REngine/Rserve/protocol/RPacket.java
Restructured R repository for Tycho POMless builds.
[simantics/r.git] / bundles / org.simantics.r.scl / src / org / rosuda / REngine / Rserve / protocol / RPacket.java
1 package org.rosuda.REngine.Rserve.protocol;
2
3 // JRclient library - client interface to Rserve, see http://www.rosuda.org/Rserve/
4 // Copyright (C) 2004 Simon Urbanek
5 // --- for licensing information see LICENSE file in the original JRclient distribution ---
6
7 /** small class encapsulating packets from/to Rserv
8     @version $Id$
9 */
10 public class RPacket {
11     int cmd;
12     byte[] cont;
13
14     /** construct new packet
15         @param Rcmd command
16         @param Rcont content */
17     public RPacket(int Rcmd, byte[] Rcont) {
18         cmd=Rcmd; cont=Rcont;
19     }
20     
21     /** get command
22         @return command */
23     public int getCmd() { return cmd; }
24     
25     /** check last response for RESP_OK
26         @return <code>true</code> if last response was OK */
27     public boolean isOk() { return ((cmd&15)==1); }
28     
29     /** check last response for RESP_ERR
30         @return <code>true</code> if last response was ERROR */
31     public boolean isError() { return ((cmd&15)==2); }
32     
33     /** get status code of last response
34         @return status code returned on last response */
35     public int getStat() { return ((cmd>>24)&127); }
36
37     /** get content
38         @return inner package content */
39     public byte[] getCont() { return cont; }
40
41     public String toString() { return "RPacket[cmd="+cmd+",len="+((cont==null)?"<null>":(""+cont.length))+"]"; }
42 }