+ // a.k.a. in.readableBytes() from the first EOM byte
+ final int readableBytes = writerIndex - eomIndex;
+ if (readableBytes < EOM_LENGTH) {
+ // Not enough bytes to contain a delimiter, bail out
+ LOG.trace("Context {} buffer {} has only {} new bytes", ctx, in, readableBytes);
+ bodyLength = eomIndex - readerIndex;
+ return null;
+ }
+
+ // Check for EOM match
+ if (isEom(in, eomIndex)) {
+ final int frameLength = eomIndex - readerIndex;
+ LOG.debug("Context {} buffer {} frame detected: length {}", ctx, in, frameLength);
+ final var ret = in.readRetainedSlice(frameLength);
+ in.skipBytes(EOM_LENGTH);
+ bodyLength = 0;
+ return ret;
+ }
+
+ // No match: move one byte past eomIndex and repeat
+ searchIndex = eomIndex + 1;
+ LOG.trace("Context {} buffer {} restart at {}", ctx, in, searchIndex);
+ }
+ }