private static @Nullable <T> GistRecord<T> nextRecordOrNull(@NotNull AttributeInputStream stream,
                                                                @NotNull DataExternalizer<T> externalizer) throws IOException {
      if (stream.available() == 0) {
        return null;
      }
      //gist record format: <enumerated projectId:varint>, <gistStamp:int>, <valueKind:byte>, <payload...>?
      //  projectId: varint (enumerated projectId)
      //  gistStamp: int
      //  valueKind: byte (0,1,2)
      //             0: (gist value is null)
      //             1: (gist value is stored inline, in VFS attribute)
      //                payload = gistData: byte[]
      //             2: (gist value is stored in a dedicated file '<HUGE_GIST_DIR>/<fileId>.<gistPathSuffix>')
      //                payload = gistPathSuffix: UTF8 string (as per IOUtil.readUTF)
      String persistedProjectId = stream.readEnumeratedString();
      int persistedGistStamp = stream.readInt();
      int persistedGistValueKind = stream.read();
      switch (persistedGistValueKind) {
        case VALUE_KIND_NULL -> {
          return new GistRecord<>(
            persistedProjectId,
            persistedGistStamp,
            (T)null
          );
        }
        case VALUE_KIND_INLINE -> {
          T gistValue = externalizer.read(stream);
          return new GistRecord<>(
            persistedProjectId,
            persistedGistStamp,
            gistValue
          );
        }
        case VALUE_KIND_IN_DEDICATED_FILE -> {
          String gistPathSuffix = IOUtil.readUTF(stream);
          return new GistRecord<>(
            persistedProjectId,
            persistedGistStamp,
            gistPathSuffix
          );
        }

        default -> throw new IOException("Unrecognized gist.valueKind(=" + persistedGistValueKind + "): incorrect (outdated?) gist format");
      }
    }
private static @Nullable <T> GistRecord<T> nextRecordOrNull(@NotNull AttributeInputStream stream,
                                                                @NotNull DataExternalizer<T> externalizer)