code: public static int byteBufferSizeFor(INDArray arr) {
          if (!arr.isCompressed()) {
              ByteBuffer buffer = arr.data().pointer().asByteBuffer().order(ByteOrder.nativeOrder());
              ByteBuffer shapeBuffer = arr.shapeInfoDataBuffer().pointer().asByteBuffer().order(ByteOrder.nativeOrder());
              //2 four byte ints at the beginning
              int twoInts = 8;
              return twoInts + buffer.limit() + shapeBuffer.limit();
          } else {
              CompressedDataBuffer compressedDataBuffer = (CompressedDataBuffer) arr.data();
              CompressionDescriptor descriptor = compressedDataBuffer.getCompressionDescriptor();
              ByteBuffer codecByteBuffer = descriptor.toByteBuffer();
              ByteBuffer buffer = arr.data().pointer().asByteBuffer().order(ByteOrder.nativeOrder());
              ByteBuffer shapeBuffer = arr.shapeInfoDataBuffer().pointer().asByteBuffer().order(ByteOrder.nativeOrder());
              int twoInts = 2 * 4;
              return twoInts + buffer.limit() + shapeBuffer.limit() + codecByteBuffer.limit();
          }
      }
docs: Returns the byte buffer size for the given
  ndarray. This is an auxillary method
  for determining the size of the buffer
  size to allocate for sending an ndarray via
  the aeron media driver.
  
  The math break down for uncompressed is:
  2 ints for rank of the array and an ordinal representing the data opType of the data buffer
  The rest is in order:
  shape information
  data buffer
  
  The math break down for compressed is:
  2 ints for rank and an ordinal representing the data opType for the data buffer
  
  The rest is in order:
  shape information
  codec information
  data buffer
  
  @param arr the array to compute the size for
  @return the size of the byte buffer that was allocated