code: @VisibleForTesting
    String trimStartEndElements(
        String serializedRequest, boolean isFirstRequest, boolean isLastRequest) {
      int beginIndex = 0;
      int endIndex = serializedRequest.length();
      if (!isFirstRequest) {
        // Move the beginIndex (inclusive) to the character after the first opening tag, which
        // should be a "<mutate>" tag, possibly with namespace declarations.
        beginIndex = serializedRequest.indexOf('>') + 1;
        Preconditions.checkArgument(
            serializedRequest.substring(0, beginIndex - 1).contains("mutate"),
            "Did not find an opening <mutate> element at the beginning of serialized request: %s",
            serializedRequest);
      }
      if (!isLastRequest) {
        // Move the endIndex (exclusive) to the beginning of the first closing tag, which
        // should be a "</mutate>" tag.
        endIndex = serializedRequest.lastIndexOf('<');
        Preconditions.checkArgument(serializedRequest.substring(endIndex).contains("mutate"),
            "Did not find a closing </mutate> element at the end of serialized request: %s",
            serializedRequest);
      }
      return serializedRequest.substring(beginIndex, endIndex);
    }
docs: Returns {@code serializedRequest} with the start or end {@code mutate} element removed,
  depending on whether the request is the first and/or last request.
  
  <p>Callers should ensure that {@code serializedRequest} does <em>not</em> contain an XML
  declaration.