@@ -36,7 +36,19 @@ private DataHighlightInstruction(Map<Integer, Integer> highlightOrders, List<Buf
3636 public List <Highlight <?>> write (int curWriterIndex , @ Nullable B receivedByteBuf , B buf , V value ) {
3737 List <Highlight <?>> highlights = Lists .newArrayList ();
3838
39+ boolean ignoreRemaining = false ;
40+
3941 for (var instruction : this .instructions ) {
42+ if (instruction instanceof RestartInstruction ) {
43+ ignoreRemaining = false ; // resume
44+ continue ;
45+ }
46+
47+ if (ignoreRemaining ) {
48+ highlights .add (NO_HIGHLIGHT );
49+ continue ;
50+ }
51+
4052 if (instruction instanceof SameRefInstruction <?, ?> sameRef ) {
4153 highlights .add (highlights .get (sameRef .getHighlightIndex ())); // Same as the previous highlight specified by the index.
4254 continue ;
@@ -56,7 +68,7 @@ public List<Highlight<?>> write(int curWriterIndex, @Nullable B receivedByteBuf,
5668 }
5769
5870 if (!instruction .shouldContinue (receivedByteBuf , value )) {
59- break ;
71+ ignoreRemaining = true ;
6072 }
6173 }
6274
@@ -115,6 +127,11 @@ public DataHighlightInstructionBuilder<B, T> sameAs(int highlightIndex) {
115127 return this ;
116128 }
117129
130+ public DataHighlightInstructionBuilder <B , T > restart () {
131+ this .instructions .add (RestartInstruction .INSTANCE );
132+ return this ;
133+ }
134+
118135 public <V > DataHighlightInstructionBuilder <B , T > constant (Descriptor <? super B , V > descriptor ) {
119136 return this .constant (descriptor .withDescription (v -> "" ));
120137 }
@@ -185,11 +202,11 @@ public <V> DataHighlightInstructionBuilder<B, T> jsonCodec(Codec<V> codec, Funct
185202 return this ;
186203 }
187204
188- public <V > DataHighlightInstructionBuilder <B , T > packetCodec (PacketCodec <B , V > codec , Function <T , V > fieldGetter ) {
205+ public <V > DataHighlightInstructionBuilder <B , T > packetCodec (PacketCodec <? super B , V > codec , Function <T , V > fieldGetter ) {
189206 return this .packetCodec (codec , v -> "" , fieldGetter );
190207 }
191208
192- public <V > DataHighlightInstructionBuilder <B , T > packetCodec (PacketCodec <B , V > codec , Function <V , String > descriptor , Function <T , V > fieldGetter ) {
209+ public <V > DataHighlightInstructionBuilder <B , T > packetCodec (PacketCodec <? super B , V > codec , Function <V , String > descriptor , Function <T , V > fieldGetter ) {
193210 this .instructions .add (BufInstruction .writeAndGuess ((byteBuf , o ) -> codec .encode (byteBuf , fieldGetter .apply (o )), o -> descriptor .apply (fieldGetter .apply (o ))));
194211 return this ;
195212 }
0 commit comments