@@ -357,26 +357,23 @@ public static TopDocsAndMaxScore readTopDocs(StreamInput in) throws IOException
357357 public static FieldDoc readFieldDoc (StreamInput in ) throws IOException {
358358 Comparable [] cFields = new Comparable [in .readVInt ()];
359359 for (int j = 0 ; j < cFields .length ; j ++) {
360- byte type = in .readByte ();
361- cFields [j ] = switch (type ) {
362- case 0 -> null ;
363- case 1 -> in .readString ();
364- case 2 -> in .readInt ();
365- case 3 -> in .readLong ();
366- case 4 -> in .readFloat ();
367- case 5 -> in .readDouble ();
368- case 6 -> in .readByte ();
369- case 7 -> in .readShort ();
370- case 8 -> in .readBoolean ();
371- case 9 -> in .readBytesRef ();
372- case 10 -> new BigInteger (in .readString ());
373- default -> throw new IOException ("Can't match type [" + type + "]" );
374- };
360+ cFields [j ] = readTypedValue (in );
375361 }
376362 return new FieldDoc (in .readVInt (), in .readFloat (), cFields );
377363 }
378364
379365 public static Comparable readSortValue (StreamInput in ) throws IOException {
366+ return readTypedValue (in );
367+ }
368+
369+ /**
370+ * Reads a typed value from the stream based on a type byte prefix.
371+ *
372+ * @param in the input stream
373+ * @return the deserialized Comparable value
374+ * @throws IOException if reading fails or type is unknown
375+ */
376+ private static Comparable readTypedValue (StreamInput in ) throws IOException {
380377 byte type = in .readByte ();
381378 return switch (type ) {
382379 case 0 -> null ;
0 commit comments