code: @Override
      public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out)
              throws Exception {
          int terminatorPos = in.indexOf(terminator);
  
          if (terminatorPos >= 0) {
              int limit = in.limit();
              IoBuffer product;
  
              if (in.position() < terminatorPos) {
                  in.limit(terminatorPos);
  
                  if (buffer == null) {
                      product = in.slice();
                  } else {
                      buffer.put(in);
                      product = buffer.flip();
                      buffer = null;
                  }
  
                  in.limit(limit);
              } else {
                  // When input contained only terminator rather than actual data...
                  if (buffer == null) {
                      product = (IoBuffer) allocator.wrap(allocator.allocate(0));
                  } else {
                      buffer.flip();
                      product = buffer;
                      buffer = null;
                  }
              }
              in.position(terminatorPos + 1);
              return finishDecode(product, out);
          }
  
          if (buffer == null) {
              buffer = (IoBuffer) allocator.wrap(allocator.allocate(in.remaining())).setAutoExpander(allocator);
          }
  
          buffer.put(in);
          return this;
      }
docs: {@inheritDoc}