code: @Override
      protected void encode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
          if (buf.readableBytes() > MAX_MESSAGE_SIZE) {
              throw new EncoderException("Message too big. " + buf.readableBytes() + " bytes (max " + MAX_MESSAGE_SIZE + ")");
          }
  
          if (buf.readableBytes() <= MAX_CHUNK_SIZE) {
              // Need to retain() the buffer here to avoid releasing the buffer too early.
              out.add(buf.retain());
          } else {
              final Chunker chunker = new Chunker(buf.readableBytes());
  
              try {
                  while (buf.readableBytes() > 0) {
                      if (buf.readableBytes() >= MAX_CHUNK_SIZE) {
                          out.add(chunker.nextChunk(buf.readSlice(MAX_CHUNK_SIZE)));
                      } else {
                          out.add(chunker.nextChunk(buf.readSlice(buf.readableBytes())));
                      }
                  }
              } catch (Exception e) {
                  LOG.error("Chunk encoder error", e);
                  buf.release();
              }
          }
      }
docs: {@inheritDoc}