public static Pair<ReplicateWALEntryRequest, ExtendedCellScanner> buildReplicateWALEntryRequest(
    final Entry[] entries, byte[] encodedRegionName, String replicationClusterId,
    Path sourceBaseNamespaceDir, Path sourceHFileArchiveDir) {
    // Accumulate all the Cells seen in here.
    List<List<? extends ExtendedCell>> allCells = new ArrayList<>(entries.length);
    int size = 0;
    WALEntry.Builder entryBuilder = WALEntry.newBuilder();
    ReplicateWALEntryRequest.Builder builder = ReplicateWALEntryRequest.newBuilder();

    for (Entry entry : entries) {
      entryBuilder.clear();
      WALProtos.WALKey.Builder keyBuilder;
      try {
        keyBuilder = entry.getKey().getBuilder(WALCellCodec.getNoneCompressor());
      } catch (IOException e) {
        throw new AssertionError(
          "There should not throw exception since NoneCompressor do not throw any exceptions", e);
      }
      if (encodedRegionName != null) {
        keyBuilder.setEncodedRegionName(UnsafeByteOperations.unsafeWrap(encodedRegionName));
      }
      entryBuilder.setKey(keyBuilder.build());
      WALEdit edit = entry.getEdit();
      // TODO: avoid this cast
      List<ExtendedCell> cells = (List) edit.getCells();
      // Add up the size. It is used later serializing out the kvs.
      for (Cell cell : cells) {
        size += PrivateCellUtil.estimatedSerializedSizeOf(cell);
      }
      // Collect up the cells
      allCells.add(cells);
      // Write out how many cells associated with this entry.
      entryBuilder.setAssociatedCellCount(cells.size());
      builder.addEntry(entryBuilder.build());
    }

    if (replicationClusterId != null) {
      builder.setReplicationClusterId(replicationClusterId);
    }
    if (sourceBaseNamespaceDir != null) {
      builder.setSourceBaseNamespaceDirPath(sourceBaseNamespaceDir.toString());
    }
    if (sourceHFileArchiveDir != null) {
      builder.setSourceHFileArchiveDirPath(sourceHFileArchiveDir.toString());
    }

    return new Pair<>(builder.build(), getCellScanner(allCells, size));
  }
Create a new ReplicateWALEntryRequest from a list of WAL entries
@param entries                the WAL entries to be replicated
@param encodedRegionName      alternative region name to use if not null
@param replicationClusterId   Id which will uniquely identify source cluster FS client
                              configurations in the replication configuration directory
@param sourceBaseNamespaceDir Path to source cluster base namespace directory
@param sourceHFileArchiveDir  Path to the source cluster hfile archive directory
@return a pair of ReplicateWALEntryRequest and a CellScanner over all the WALEdit values found.
hbase-server/src/main/java/org/apache/hadoop/hbase/protobuf/ReplicationProtobufUtil.java