protected ByteBuffer readResponse(int expected) { ByteBuffer def = ByteBuffer.allocate(8); def.order(myOrder); readAll(def); def.rewind(); short version = def.getShort(); short _expected = def.getShort(); if (version != VERSION) { errorReturned = VERSION_ERROR; throw new IOException("Invalid VERSION returned."); } else if (_expected != expected) { errorReturned = BUFFER_READ_ERROR; //throw new IOException("Error returned from FieldTrip buffer server."); } else { errorReturned = NO_ERROR; } int size = def.getInt(); ByteBuffer buf = ByteBuffer.allocate(size); buf.order(myOrder); readAll(buf); buf.rewind(); return(buf); }
public void putData(float[,] data) { int nSamples = data.GetLength(0); if (nSamples == 0) { return; } int nChans = data.GetLength(1); if (nChans == 0) { return; } ByteBuffer buf = preparePutData(nChans, nSamples, DataType.FLOAT32); float[] rowData; for (int i = 0; i < nSamples; i++) { rowData = getRow <float>(data, i); buf.asFloatBuffer().put(rowData); } buf.rewind(); lock (this) { writeAll(buf); readResponse(PUT_OK); } }
public void putData(double[,] data) { int nSamples = data.GetLength(0); if (nSamples == 0) { return; } int nChans = data.GetLength(1); if (nChans == 0) { return; } ByteBuffer buf = preparePutData(nChans, nSamples, DataType.FLOAT64); double[] rowData; for (int i = 0; i < nSamples; i++) { rowData = getRow <double>(data, i); buf.asDoubleBuffer().put(rowData); } buf.rewind(); writeAll(buf); readResponse(PUT_OK); }
public void putRawData(int nSamples, int nChans, int dataType, byte[] data) { if (nSamples == 0) { return; } if (nChans == 0) { return; } if (data.Length != nSamples * nChans * DataType.wordSize[dataType]) { errorReturned = BUFFER_NOT_MATCH_DESCRIPTION_ERROR; throw new IOException("Raw buffer does not match data description"); } ByteBuffer buf = preparePutData(nChans, nSamples, dataType); buf.put(data); buf.rewind(); lock (this) { writeAll(buf); readResponse(PUT_OK); } }