public static Optional<Tag> getTag(ExtendedCell cell, byte type) {
    boolean bufferBacked = cell instanceof ByteBufferExtendedCell;
    int length = cell.getTagsLength();
    int offset =
      bufferBacked ? ((ByteBufferExtendedCell) cell).getTagsPosition() : cell.getTagsOffset();
    int pos = offset;
    while (pos < offset + length) {
      int tagLen;
      if (bufferBacked) {
        ByteBuffer tagsBuffer = ((ByteBufferExtendedCell) cell).getTagsByteBuffer();
        tagLen = ByteBufferUtils.readAsInt(tagsBuffer, pos, TAG_LENGTH_SIZE);
        if (ByteBufferUtils.toByte(tagsBuffer, pos + TAG_LENGTH_SIZE) == type) {
          return Optional.of(new ByteBufferTag(tagsBuffer, pos, tagLen + TAG_LENGTH_SIZE));
        }
      } else {
        tagLen = Bytes.readAsInt(cell.getTagsArray(), pos, TAG_LENGTH_SIZE);
        if (cell.getTagsArray()[pos + TAG_LENGTH_SIZE] == type) {
          return Optional
            .of(new ArrayBackedTag(cell.getTagsArray(), pos, tagLen + TAG_LENGTH_SIZE));
        }
      }
      pos += TAG_LENGTH_SIZE + tagLen;
    }
    return Optional.empty();
  }
Retrieve Cell's first tag, matching the passed in type
@param cell The Cell
@param type Type of the Tag to retrieve
@return Optional, empty if there is no tag of the passed in tag type
hbase-common/src/main/java/org/apache/hadoop/hbase/PrivateCellUtil.java