package at.acdp.urweb.rtde.packets; import at.acdp.urweb.rtde.RTDEClient; import org.slf4j.LoggerFactory; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; public interface IRtdeData { final static org.slf4j.Logger logger = LoggerFactory.getLogger(RTDEClient.class); int getType(); int getSize(); void setReplySize(int i); T read(DataInputStream di) throws IOException; T send(DataOutputStream dos) throws IOException; default void sendHeader(DataOutputStream dos) throws IOException { dos.writeShort(getSize()); dos.writeByte(getType()); } default void readHeader(DataInputStream dis) throws IOException { setReplySize(dis.readShort()); int cmd = dis.readByte(); if(cmd==getType()) return; if (cmd==77) { int mLength=dis.readByte(); byte[] mText = new byte[mLength]; dis.readFully(mText); String m=new String(mText); logger.info(m); int sLength=dis.readByte(); byte[] sText = new byte[sLength]; dis.readFully(sText); String s=new String(sText); logger.info(s); int warning=dis.readByte(); String w=String.valueOf(warning); } else throw new IOException(String.format("Expected %d, got %d", getType(), cmd)); } }