@@ -198,12 +198,15 @@ public static String ignoredFieldName(String fieldName) {
198198 }
199199
200200 static BytesRef encodeMulti (List <NameValue > values ) {
201+ assert values .isEmpty () == false ;
201202 try {
202203 BytesStreamOutput stream = new BytesStreamOutput ();
203204 stream .writeVInt (values .size ());
205+ String fieldName = values .getFirst ().name ;
206+ stream .writeString (fieldName );
204207 for (var value : values ) {
208+ assert fieldName .equals (value .name );
205209 stream .writeVInt (value .parentOffset );
206- stream .writeString (value .name );
207210 stream .writeBytesRef (value .value );
208211 }
209212 return stream .bytes ().toBytesRef ();
@@ -216,10 +219,11 @@ static List<NameValue> decodeMulti(BytesRef value) {
216219 try {
217220 StreamInput stream = new BytesArray (value ).streamInput ();
218221 var count = stream .readVInt ();
222+ assert count >= 1 ;
223+ String fieldName = stream .readString ();
219224 List <NameValue > values = new ArrayList <>(count );
220225 for (int i = 0 ; i < count ; i ++) {
221226 int parentOffset = stream .readVInt ();
222- String fieldName = stream .readString ();
223227 BytesRef valueBytes = stream .readBytesRef ();
224228 values .add (new NameValue (fieldName , parentOffset , valueBytes , null ));
225229 }
0 commit comments