public Buffer objectToBuffer(Object obj) throws Exception { MethodCall call = (MethodCall) obj; ByteBuffer buf; switch (call.getId()) { case START: case GET_CONFIG: buf = ByteBuffer.allocate(Global.BYTE_SIZE); buf.put((byte) call.getId()); return new Buffer(buf.array()); case SET_OOB: case SET_SYNC: return new Buffer(booleanBuffer(call.getId(), (Boolean) call.getArgs()[0])); case SET_NUM_MSGS: case SET_NUM_THREADS: case SET_MSG_SIZE: case SET_ANYCAST_COUNT: return new Buffer(intBuffer(call.getId(), (Integer) call.getArgs()[0])); case GET: return new Buffer(longBuffer(call.getId(), (Long) call.getArgs()[0])); case PUT: Long long_arg = (Long) call.getArgs()[0]; byte[] arg2 = (byte[]) call.getArgs()[1]; buf = ByteBuffer.allocate( Global.BYTE_SIZE + Global.INT_SIZE + Global.LONG_SIZE + arg2.length); buf.put((byte) call.getId()) .putLong(long_arg) .putInt(arg2.length) .put(arg2, 0, arg2.length); return new Buffer(buf.array()); case SET_READ_PERCENTAGE: Double double_arg = (Double) call.getArgs()[0]; buf = ByteBuffer.allocate(Global.BYTE_SIZE + Global.DOUBLE_SIZE); buf.put((byte) call.getId()).putDouble(double_arg); return new Buffer(buf.array()); default: throw new IllegalStateException("method " + call.getMethod() + " not known"); } }