@SuppressWarnings("unchecked")
  @Override
  public int encode(PositionedByteRange dst, Object[] val) {
    if (val.length == 0) {
      return 0;
    }
    assert fields.length >= val.length;
    int end, written = 0;
    // find the last occurrence of a non-null or null and non-nullable value
    for (end = val.length - 1; end > -1; end--) {
      if (null != val[end] || (null == val[end] && !fields[end].isNullable())) {
        break;
      }
    }
    for (int i = 0; i <= end; i++) {
      written += fields[i].encode(dst, val[i]);
    }
    return written;
  }
Read the field at {@code index}. {@code src}'s position is not affected.
hbase-common/src/main/java/org/apache/hadoop/hbase/types/Struct.java