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); } }
public void putData(byte[,] 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.INT8); byte[] rowData; for (int i = 0; i < nSamples; i++) { rowData = getRow <byte>(data, i); buf.put(rowData); } buf.rewind(); writeAll(buf); readResponse(PUT_OK); }
public int read(ByteBuffer dst) { int toRead = dst.capacity(); byte[] message = new byte[toRead]; int readBytes = 0; int waitTime = 0; lock (this) { while (readBytes < toRead && waitTime < readTimeout_ms) { if (theStream.DataAvailable) // read if something to do { readBytes += theStream.Read(message, readBytes, toRead - readBytes); } else // prevent live-lock { waitTime += 2; System.Threading.Thread.Sleep(2); } } } dst.put(message, 0, readBytes); return(readBytes); }
public int read(ByteBuffer dst) { int toRead = dst.capacity(); byte[] message = new byte[toRead]; int readBytes = 0; while(readBytes<toRead){ readBytes += theStream.Read(message, readBytes, toRead-readBytes); } dst.put(message); return readBytes; }
public int read(ByteBuffer dst) { int toRead = dst.capacity(); byte[] message = new byte[toRead]; int readBytes = 0; //while(readBytes<toRead){ // this loop is uncessary -- we return number bytes read anyway... readBytes += theStream.Read(message, readBytes, toRead - readBytes); //} dst.put(message); return(readBytes); }
public int read(ByteBuffer dst) { int toRead = dst.capacity(); byte[] message = new byte[toRead]; int readBytes = 0; while (readBytes < toRead) { readBytes += theStream.Read(message, readBytes, toRead - readBytes); } dst.put(message); return(readBytes); }
public void serialize(ByteBuffer buf) { switch (type) { case DataType.CHAR: buf.putString(array.ToString()); break; case DataType.UINT8: case DataType.INT8: buf.put((byte[])array); break; case DataType.UINT16: case DataType.INT16: buf.asShortBuffer().put((short[])array); break; case DataType.UINT32: case DataType.INT32: buf.asIntBuffer().put((int[])array); break; case DataType.UINT64: case DataType.INT64: buf.asLongBuffer().put((long[])array); break; case DataType.FLOAT32: buf.asFloatBuffer().put((float[])array); break; case DataType.FLOAT64: buf.asDoubleBuffer().put((double[])array); break; } }
public void serialize(ByteBuffer buf) { switch(type) { case DataType.CHAR: buf.putString(array.ToString()); break; case DataType.UINT8: case DataType.INT8: buf.put((byte[]) array); break; case DataType.UINT16: case DataType.INT16: buf.asShortBuffer().put((short[]) array); break; case DataType.UINT32: case DataType.INT32: buf.asIntBuffer().put((int[]) array); break; case DataType.UINT64: case DataType.INT64: buf.asLongBuffer().put((long[]) array); break; case DataType.FLOAT32: buf.asFloatBuffer().put((float[]) array); break; case DataType.FLOAT64: buf.asDoubleBuffer().put((double[]) array); break; } }
public int read(ByteBuffer dst) { int toRead = dst.capacity(); byte[] message = new byte[toRead]; int readBytes = 0; //while(readBytes<toRead){ // this loop is uncessary -- we return number bytes read anyway... readBytes += theStream.Read(message, readBytes, toRead-readBytes); //} dst.put(message); return readBytes; }