public void pointTo(MemoryBuffer buf, int offset, int sizeInBytes) {
    this.buf = buf;
    this.baseOffset = offset;
    this.sizeInBytes = sizeInBytes;
    // Read the numBytes of key array from the aligned first 8 bytes as int.
    final int keyArrayBytes = buf.getInt32(offset);
    assert keyArrayBytes >= 0 : "keyArrayBytes (" + keyArrayBytes + ") should >= 0";
    final int valueArrayBytes = sizeInBytes - keyArrayBytes - 8;
    assert valueArrayBytes >= 0 : "valueArraySize (" + valueArrayBytes + ") should >= 0";

    keys.pointTo(buf, offset + 8, keyArrayBytes);
    values.pointTo(buf, offset + 8 + keyArrayBytes, valueArrayBytes);
    assert keys.numElements() == values.numElements();
  }
@Test
  public void pointTo() {
    MemoryBuffer buffer = MemoryUtils.buffer(1024);
    int writerIndex = 8; // preserve 8 byte for numBytes
    BinaryArrayWriter keyArrayWriter =
        new BinaryArrayWriter(DataTypes.arrayField(DataTypes.utf8()));
    keyArrayWriter.reset(2);
    keyArrayWriter.write(0, "k0");
    keyArrayWriter.write(1, "k1");
    buffer.copyFrom(
        writerIndex,
        keyArrayWriter.getBuffer(),
        keyArrayWriter.getStartIndex(),
        keyArrayWriter.size());
    writerIndex += keyArrayWriter.size();
    buffer.putInt64(0, keyArrayWriter.size());
    BinaryArrayWriter valueArrayWriter =
        new BinaryArrayWriter(DataTypes.arrayField(DataTypes.utf8()));
    valueArrayWriter.reset(2);
    valueArrayWriter.write(0, "v0");
    valueArrayWriter.write(1, "v1");
    buffer.copyFrom(
        writerIndex,
        valueArrayWriter.getBuffer(),
        valueArrayWriter.getStartIndex(),
        valueArrayWriter.size());
    writerIndex += valueArrayWriter.size();
    BinaryMap map = new BinaryMap(DataTypes.mapField(DataTypes.utf8(), DataTypes.utf8()));
    map.pointTo(buffer, 0, writerIndex);
    // System.out.println(map);
  }