protocol_bytes_last_read = 0;
data_bytes_last_read = 0;
long total_read = 0;
while( total_read < max_bytes ){
long bytes_read;
ByteBuffer payload_buffer = buffers[1];
if ( payload_buffer == null ){
bytes_read = transport.read( buffers, 0, 1 );
protocol_bytes_last_read += bytes_read;
if ( length_buffer.hasRemaining()){
break;
}else{
length_buffer.flip();
int size = length_buffer.getInt();
if ( size > MAX_MESSAGE_LENGTH ){
Debug.out( "Message too large for generic payload" );
throw( new IOException( "message too large" ));
}
buffers[1] = ByteBuffer.allocate( size );
length_buffer.flip();
}
}else{
bytes_read = transport.read( buffers, 1, 1 );
data_bytes_last_read += bytes_read;
if ( payload_buffer.hasRemaining()){
break;
}
payload_buffer.flip();
messages.add( new GenericMessage( msg_type, msg_desc, new DirectByteBuffer( payload_buffer ), false ));
buffers[1] = null;
}
total_read += bytes_read;
}
if ( destroyed ){
throw( new IOException( "decoder has been destroyed" ));
}
return((int) total_read );