static ScanResponse doMetaScanResponse(
     final SortedMap<byte[], Pair<HRegionInfo, ServerName>> meta,
     final AtomicLong sequenceids,
     final ScanRequest request) {
   ScanResponse.Builder builder = ScanResponse.newBuilder();
   int max = request.getNumberOfRows();
   int count = 0;
   Map<byte[], Pair<HRegionInfo, ServerName>> tail =
       request.hasScan() ? meta.tailMap(request.getScan().getStartRow().toByteArray()) : meta;
   ClientProtos.Result.Builder resultBuilder = ClientProtos.Result.newBuilder();
   for (Map.Entry<byte[], Pair<HRegionInfo, ServerName>> e : tail.entrySet()) {
     // Can be 0 on open of a scanner -- i.e. rpc to setup scannerid only.
     if (max <= 0) break;
     if (++count > max) break;
     HRegionInfo hri = e.getValue().getFirst();
     ByteString row = HBaseZeroCopyByteString.wrap(hri.getRegionName());
     resultBuilder.clear();
     resultBuilder.addCell(getRegionInfo(row, hri));
     resultBuilder.addCell(getServer(row, e.getValue().getSecond()));
     resultBuilder.addCell(getStartCode(row));
     builder.addResults(resultBuilder.build());
     // Set more to false if we are on the last region in table.
     if (hri.getEndKey().length <= 0) builder.setMoreResults(false);
     else builder.setMoreResults(true);
   }
   // If no scannerid, set one.
   builder.setScannerId(
       request.hasScannerId() ? request.getScannerId() : sequenceids.incrementAndGet());
   return builder.build();
 }
 private GetResponse doGetResponse(GetRequest request) {
   ClientProtos.Result.Builder resultBuilder = ClientProtos.Result.newBuilder();
   ByteString row = request.getGet().getRow();
   resultBuilder.addCell(getStartCode(row));
   GetResponse.Builder builder = GetResponse.newBuilder();
   builder.setResult(resultBuilder.build());
   return builder.build();
 }
 static GetResponse doMetaGetResponse(
     final SortedMap<byte[], Pair<HRegionInfo, ServerName>> meta, final GetRequest request) {
   ClientProtos.Result.Builder resultBuilder = ClientProtos.Result.newBuilder();
   ByteString row = request.getGet().getRow();
   Pair<HRegionInfo, ServerName> p = meta.get(row.toByteArray());
   if (p == null) {
     if (request.getGet().getClosestRowBefore()) {
       byte[] bytes = row.toByteArray();
       SortedMap<byte[], Pair<HRegionInfo, ServerName>> head =
           bytes != null ? meta.headMap(bytes) : meta;
       p = head == null ? null : head.get(head.lastKey());
     }
   }
   if (p != null) {
     resultBuilder.addCell(getRegionInfo(row, p.getFirst()));
     resultBuilder.addCell(getServer(row, p.getSecond()));
   }
   resultBuilder.addCell(getStartCode(row));
   GetResponse.Builder builder = GetResponse.newBuilder();
   builder.setResult(resultBuilder.build());
   return builder.build();
 }
 static MultiResponse doMultiResponse(
     final SortedMap<byte[], Pair<HRegionInfo, ServerName>> meta,
     final AtomicLong sequenceids,
     final MultiRequest request) {
   // Make a response to match the request.  Act like there were no failures.
   ClientProtos.MultiResponse.Builder builder = ClientProtos.MultiResponse.newBuilder();
   // Per Region.
   RegionActionResult.Builder regionActionResultBuilder = RegionActionResult.newBuilder();
   ResultOrException.Builder roeBuilder = ResultOrException.newBuilder();
   for (RegionAction regionAction : request.getRegionActionList()) {
     regionActionResultBuilder.clear();
     // Per Action in a Region.
     for (ClientProtos.Action action : regionAction.getActionList()) {
       roeBuilder.clear();
       // Return empty Result and proper index as result.
       roeBuilder.setResult(ClientProtos.Result.getDefaultInstance());
       roeBuilder.setIndex(action.getIndex());
       regionActionResultBuilder.addResultOrException(roeBuilder.build());
     }
     builder.addRegionActionResult(regionActionResultBuilder.build());
   }
   return builder.build();
 }