code: @SuppressWarnings("unchecked")
      @Nonnull
      public static <T> Optional<T> optionalInMessage(PMessage message, PField... fields) {
          if (fields == null || fields.length == 0) {
              throw new IllegalArgumentException("No fields arguments.");
          }
          PField field = fields[0];
          if (!message.has(field.getId())) {
              return Optional.empty();
          }
  
          if (fields.length > 1) {
              if (field.getType() != PType.MESSAGE) {
                  throw new IllegalArgumentException("Field " + field.getName() + " is not a message.");
              }
              return optionalInMessage((PMessage) message.get(field), Arrays.copyOfRange(fields, 1, fields.length));
          } else {
              return Optional.of((T) message.get(field.getId()));
          }
      }
docs: Get a field value from a message with optional chaining. If the field is
  not set, or any message in the chain leading up to the last message is
  missing, it will return an empty optional. Otherwise the leaf field value.
  
  Note that this will only check for MESSAGE type if the message is present
  and needs to be looked up in.
  
  @param message The message to start looking up field values in.
  @param fields Fields to look up in the message.
  @param <T> The expected leaf value type.
  @return Optional field value.