private static BinaryArray fromPrimitiveArray(Object arr, int offset, int length, Field field) {
    BinaryArray result = new BinaryArray(field);
    final long headerInBytes = calculateHeaderInBytes(length);
    final long valueRegionInBytes = result.elementSize * length;
    final long totalSize = headerInBytes + valueRegionInBytes;
    if (totalSize > Integer.MAX_VALUE) {
      throw new UnsupportedOperationException(
          "Cannot convert this array to binary format as " + "it's too big.");
    }

    final byte[] data = new byte[(int) totalSize];
    Platform.putLong(data, Platform.BYTE_ARRAY_OFFSET, length);
    Platform.copyMemory(
        arr, offset, data, Platform.BYTE_ARRAY_OFFSET + headerInBytes, valueRegionInBytes);

    MemoryBuffer memoryBuffer = MemoryUtils.wrap(data);
    result.pointTo(memoryBuffer, 0, (int) totalSize);
    return result;
  }
@Test
  public void fromPrimitiveArray() {
    int[] arr = new int[] {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2};
    BinaryArray.fromPrimitiveArray(arr);
    BinaryArrayWriter writer = new BinaryArrayWriter(DataTypes.PRIMITIVE_INT_ARRAY_FIELD);
    writer.reset(arr.length);
    writer.fromPrimitiveArray(arr);
    writer.toArray();
  }